Persistent rightBarButtonItem Property of UINavigationItem(UINavigationItem 的持久 rightBarButtonItem 属性)
问题描述
这可能是一个愚蠢的问题,但是否可以在 UINavigationController
管理的多个视图中保持正确的 UIBarButtonItem
?我有一系列经常共享相同右侧 UIBarButtonItem
的视图,但是当我将新视图推送到我的 UINavigationController
时,我每次都必须重新定义按钮,即使它没有改变.大多数情况下,从一个视图到下一个视图的明显过渡动画让我感到困扰,因为完全相同的按钮会短暂地淡出然后又回来,这是不必要的,因为没有实际的视觉变化.我是否应该考虑只添加一个 UIButton
作为我的 UINavigationBar
的子视图并以这种方式完成右栏按钮"效果?
This may be a stupid question, but is it possible to keep a right UIBarButtonItem
across multiple views managed by a UINavigationController
? I have a progression of views that often share the same right UIBarButtonItem
, but when I push a new view to my UINavigationController
, I have to redefine the button every time, even if it hasn't changed. Mostly, the noticeable transitional animation from one view to the next is what bothers me because the exact same button briefly fades out then back in, which is unnecessary since there is no actual visual change. Should I consider just adding a UIButton
as a subview of my UINavigationBar
and accomplish a "right bar button" effect this way?
推荐答案
我们在我们的应用程序中做到了这一点.我们创建了一个 UIBarButtonItem,当用户导航时我们从一个 UIViewController 交换到另一个.诀窍是使用 UINavigationControllerDelegate、navigationController:willShowViewController:animated: 方法.我们将传出的 UIViewController 的 rightBarButtonItem 设置为 nil,将传入的控制器的 rightBarButtonItem 设置为您的按钮.管理起来很痛苦,但它确实有效.
We did this in our app. We created a single UIBarButtonItem that we swap from one UIViewController to another as the user navigates. The trick was to use UINavigationControllerDelegate, the navigationController:willShowViewController:animated: method. We set the outgoing UIViewController's rightBarButtonItem to nil and the incoming controller's rightBarButtonItem to your button. It's a pain to manage, but it works.
这篇关于UINavigationItem 的持久 rightBarButtonItem 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UINavigationItem 的持久 rightBarButtonItem 属性
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01