【问题标题】:Is it possible to use Core Animation to fade out a UIBarButtonItem?是否可以使用 Core Animation 淡出 UIBarButtonItem?
【发布时间】:2013-05-23 13:09:45
【问题描述】:

我很好奇,是否有可能以某种方式交织核心动画以“淡出” UIBarButtonItem?我有一个 tableView,我用两个不同的数据源表示。一旦触发了特定的数据源,我想淡出当前的 UIToolBar 选项并淡入新的选项。

感谢您为我指明正确的方向。

【问题讨论】:

    标签: iphone objective-c cocoa-touch core-animation


    【解决方案1】:

    如果您确实使用的是 UIToolbar(注意小写的“b”)而不是 UINavigationBar,有一种非常简单的方法可以更改按钮并让过渡自动淡出,而不会下降到 Core Animation。

    如果您使用的是 Interface Builder,则需要在代码中引用工具栏。在 IB 中创建一个 IBOutlet 属性并将工具栏链接到它:

    @property (nonatomic, retain) IBOutlet UIToolbar *toolbar;
    

    这将允许您将 UIToolbar 引用为 self.toolbar。然后,创建新按钮并将它们添加到 NSArray 并将其传递给 -[UIToolbar setItems:animated:] 方法,如下所示:

    UIBarButtonItem *newItem = [[[UIBarButtonItem alloc] 
                                    initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                                    target:self 
                                    action:@selector(handleTap:)] autorelease];
    NSArray *newButtons = [NSArray arrayWithObjects:newItem, nil];
    [self.toolbar setItems:newButtons animated:YES];
    

    【讨论】:

    • 在谷歌搜索时发现了这篇文章 - 注意:我为此目的使用了一个 [self.navigationItem setLeftBarButtonItem:myBarButton animated:YES] 方法。谢谢!
    【解决方案2】:

    我不相信有办法控制 UIBarButtonItem 上的 alpha,但 UIToolbar 类已经有一个方法来支持你正在尝试做的事情:-setItems:animated:。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多