簡體   English   中英

ios-iPhone:像本地ios鬧鍾應用程序一樣進行編輯時,如何創建動畫UItableviewcell

[英]ios - iphone: How to create animation UItableviewcell when edit like native ios alarm clock app

我已經制作了一個類似於iPhone / iPod上的默認鬧鍾的鬧鍾。 但是我不知道如何像本地ios時鍾應用程序一樣編輯時如何創建動畫UItableviewcell。請幫助我。 謝謝

這樣的動畫。

在此處輸入圖片說明

[tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

http://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/reloadSections:withRowAnimation

其中UITableViewRowAnimation可以是以下之一:

typedef enum {
UITableViewRowAnimationFade,
UITableViewRowAnimationRight,
UITableViewRowAnimationLeft,
UITableViewRowAnimationTop,
UITableViewRowAnimationBottom,
UITableViewRowAnimationNone,
UITableViewRowAnimationMiddle,
UITableViewRowAnimationAutomatic = 100
} UITableViewRowAnimation;

http://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITableViewRowAnimation

我看到的是控件被隱藏了。

UITableView和UITableViewCell類都具有一個稱為的屬性:

editing

以及稱為:

- (void) setEditing : (BOOL) editing animated : (BOOL) animated;

這兩個都可用於將UITableView / UITableViewCell置於“編輯”模式。 該屬性可用於創建UITableView / UITableViewCell並將其設置為“編輯”模式,然后再添加到視圖層次結構中。

但是,該方法雖然也可以用於通過編程實現相同的目的,但也可以用於覆蓋/增強UITableView / UITableViewCell的“編輯”行為。 在這種情況下,可以由UITableViewCell使用它,通過UITableViewCell已被設置為“編輯”模式這一事實,通過UITableViewCell屬於其自己的UITableView進行通知:

- (void) setEditing : (BOOL) editing animated : (BOOL) animated
{ // setEditing:animated: ()
    mySwitchView = [[self contentView] viewWithTag : 100];
    CGFloat alphaValue = editing ? 0.0f : 1.0f;

    [UIView animateWithDuration : 3.0f
                     animations : ^(void)
                                 {
                                     [mySlideView setAlpha : alphaValue];
                                 }
} // setEditing:animated: ()

因此,如果這是Apple提供的UTableViewCell類型之一。 為了使我們的任何控件成為UITableViewCell的一部分,需要將其添加到由UITableViewDataSource提供的UITableView方法中的UITableViewCell的內容視圖中:

- (UITableViewCell*) tableView : (UITableView*) cellForRowAtIndexPath : (NSIndexPath*) indexPath
{ // tableView:cellForRowAtIndexPath: ()
    static cellIdentifier = @"cell-identifier";

    UISwitchView*    switchView = nil;
    UITableViewCell* cell       = [tableView dequeueReusableCellWithIdentifier : cellIdentifier];

    if (cell == nil)
    { // if ()
        switchView = [[UISwitchView     alloc] initWithFrame : CGRectZero];
        cell       = [[[UITableViewCell alloc] initWithStyle : UITableViewCellStyleDefault
                                             reuseIdentifier : cellIdentifier] autorelease];
        [switchView setTag : 100];
        [[cell contentView] addSubview : switchView];

        [switchView release];

        switchView = nil;
    } // if ()

    return (cell);
} // tableView:cellForRowAtIndexPath: ()

我希望這能回答您的問題。

干杯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM