ios - 显示/隐藏位于 UIToolbar 中间的 UIBarButtonItem

标签 ios cocoa-touch uibarbuttonitem uitoolbar

我在 StackOverflow 上阅读了几个关于此主题的类似问题,但没有一个适用于我的情况。

我的应用程序上有一个 UIToolbar。工具栏的布局如下所示。

(Button #1) (Button #2) (Button #3) <--- Flex Controller ---> (Button #4)

显示/隐藏 Button #3 UIBarButtonItem 的最有效方法是什么,因为它位于 UIToolbar 的中间?

跟进

我知道 setItems:Animated 方法,但这似乎有问题,因为我所有的按钮都通过 IB 连接并且它们具有关联的 IBAction。

这是否意味着我因此需要找到一种方法在隐藏时保留我的 Button #3(因为我使用的是 ARC?)我正在寻找添加和删除这些按钮的最优化/最有效的方法对象。如果我每次必须显示/隐藏我的#3 按钮时都必须重新创建此列表,这就是我要做的。

这看起来效率很低。

最佳答案

查看UIToolBar.h,有如下方法:

- (void)setItems:(NSArray *)items animated:(BOOL)animated;   // will fade in or out or reorder and adjust spacing

你应该能够做类似的事情:

NSMutableArray *items = [toolBar.items mutableCopy];
[items removeObjectAtIndex:2];
[toolBar setItems:items animated:YES];

看看是否符合您的要求

关于ios - 显示/隐藏位于 UIToolbar 中间的 UIBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9587862/

相关文章:

ios - 添加 UIImageView 作为 UILabel 的 subview ,图像不显示

iphone - 从 XCODE 中使用 SVN 的 BLAME 命令

ios - 如何隐藏底部工具栏

iphone - UIBarButtonItem 偏移量

ios - - [UIImage resizableImageWithCapInsets :] strange behavior

objective-c - 是否有 iTunes Connect Game Center REST API?

ios - 从 View 层次结构中删除 subview 并将其删除的正确方法是什么?

ios - 如何在 iOS 7 中设置 UIBarButtonItem 选中或突出显示的图像或色调颜色?

XCODE:从源代码的 full_settings.xcconfig 访问数据

ios - UILabel 文字划过角度