本文介绍了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交换到另一个UIViewBtroller。诀窍是使用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属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:42