简体   繁体   English

ios-iPhone:像本地ios闹钟应用程序一样进行编辑时,如何创建动画UItableviewcell

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

I have make a alarm clock like default alarm clock on iphone/ipod. 我已经制作了一个类似于iPhone / iPod上的默认闹钟的闹钟。 But I dont know How to create animation UItableviewcell when edit like native ios clock app.Please help me. 但是我不知道如何像本地ios时钟应用程序一样编辑时如何创建动画UItableviewcell。请帮助我。 thanks 谢谢

Animation like this. 这样的动画。

在此处输入图片说明

[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 : http://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/reloadSections:withRowAnimation

where UITableViewRowAnimation ca be one of these: 其中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 http://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITableViewRowAnimation

What I see happening is that the control is being hidden. 我看到的是控件被隐藏了。

Both the UITableView and the UITableViewCell classes have a property called: UITableView和UITableViewCell类都具有一个称为的属性:

editing

as well as a method called: 以及称为:

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

Both of these may be used to place a UITableView/UITableViewCell in "editing" mode. 这两个都可用于将UITableView / UITableViewCell置于“编辑”模式。 The property may be used to create a UITableView/UITableViewCell and set it to "editing" mode before being added to the view hierarchy. 该属性可用于创建UITableView / UITableViewCell并将其设置为“编辑”模式,然后再添加到视图层次结构中。

However, the method, while it may also be used to achieve the same thing programmatically, may also be used to override/enhance a UITableView's/UITableViewCell's "editing" behavior. 但是,该方法虽然也可以用于通过编程实现相同的目的,但也可以用于覆盖/增强UITableView / UITableViewCell的“编辑”行为。 In this case, it may be used by the UITableViewCell to be notified, by the very own UITableView of which the UITableViewCell is part, of the fact that the UITableView has been set to "Editing" mode: 在这种情况下,可以由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: ()

Therefore, if this were one of the UTableViewCell types provided by Apple. 因此,如果这是Apple提供的UTableViewCell类型之一。 In order to have any control of ours be part of the UITableViewCell, it needs to be added to the UITableViewCell's content view in the UITableView's method provided by the UITableViewDataSource: 为了使我们的任何控件成为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: ()

I do hope this answers your question. 我希望这能回答您的问题。

Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM