【问题标题】:ios - iphone: How to create animation UItableviewcell when edit like native ios alarm clock appios - iphone:如何在像本机 ios 闹钟应用程序一样编辑时创建动画 UItableviewcell
【发布时间】:2012-06-06 09:17:27
【问题描述】:

我已经在 iphone/ipod 上制作了一个类似于默认闹钟的闹钟。但我不知道如何在像本机 ios 时钟应用程序一样编辑时创建动画 UItableviewcell。请帮助我。谢谢

像这样的动画。

【问题讨论】:

    标签: iphone c object ipod-touch


    【解决方案1】:
    [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

    【讨论】:

    • 感谢您的评论。我已经过测试,但动画不像默认闹钟应用程序上的单元格
    • 是的。我愿意 。请看我的照片i594.photobucket.com/albums/tt22/hungknorton/…。我的意思是当使用点击编辑 UIswitch 将消失并出现附件复选标记。它类似于 ios 上的默认闹钟
    • 是的。我必须使用自定义的 uitableviewcell 和 uiswitch 制作这样的动画。
    • 我认为他们只是从 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator 更改 tableviewcell 附件视图;使用 uiswitch 自定义附件视图。你能测试一下吗?
    • 但是使用动画来改变。它应该以某种方式动画。另一种可能性是您将 DisclosureIndicator 用作自定义附件视图(您自己获取图像并放置它) - 然后在进入编辑模式时 - 您将它们都移动并淡出其中一个。
    【解决方案2】:

    我看到的情况是控件被隐藏了。

    UITableView 和 UITableViewCell 类都有一个名为:

    editing
    

    还有一个方法叫做:

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

    这两种方法都可用于将 UITableView/UITableViewCell 置于“编辑”模式。该属性可用于创建 UITableView/UITableViewCell 并将其设置为“编辑”模式,然后再添加到视图层次结构中。

    然而,该方法虽然也可用于以编程方式实现相同的目的,但也可用于覆盖/增强 UITableView/UITableViewCell 的“编辑”行为。在这种情况下,UITableViewCell 可能会使用它来通知 UITableViewCell 所属的 UITableView 已将 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: ()
    

    我希望这能回答你的问题。

    干杯。

    【讨论】:

      猜你喜欢
      • 2013-09-24
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      相关资源
      最近更新 更多