防止点击“返回”时出现动画导航栏中的按钮?
我的应用程序有一个导航控制器,但我不希望其中有任何动画:
要在推送视图时防止动画,这很容易,通过 pushViewController:animated: 方法
但是当我单击此子视图上的“后退”按钮时,就会出现动画! KO!我该怎么做才能阻止这个动画?
My application has a navigation controller and I don't want any animation in it :
to prevent an animation when pushing a view, it's easy, via the pushViewController:animated: method
but when I click the "back" button on this subview, there's an animation ! KO ! What can I do to prevent this animation ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这会阻止默认动画。
如果您需要自定义动画
This prevents default animation.
In case if you need a custom animation
有品类更优雅。这假设您的导航控制器对象已在您的应用程序委托中设置。只需将其放在根视图控制器中的 @implementaion 之前即可。
More elegant with a category. This assumes you navigation controller object is set in your app delegate. Just put this before your @implementaion in the root view controller.
我来 SO 寻找一个更优雅的解决方案,但到目前为止我已经(成功)做到了这一点。
基本思想:
缺点:
代码 - 在哪个类中接管动画:
...如果您还想使用自定义后退动画切入,则需要上面的最后一行,以便您可以监听导航栏并并行做出反应,例如这:
I came to SO looking for a more elegant solution, but here's how I've been (successfully) doing it so far.
The basic idea:
The downsides:
Code - in whichever class takes over for the animation:
...if you also want to cut-in with custom back animation, you need that last line above, so that you can then listen to the navbar, and react in parallel, like this:
并不是说您应该这样做,但是您可以通过在 viewController 中创建自定义
leftBarButtonItem
来覆盖标准行为。文档说您应该只在导航控制器的视图显示之前传递
NO
。请记住,不符合 iPhone 界面指南的应用程序将不会被应用商店接受。
Not that you should, however you can override the standard behaviour by creating a custom
leftBarButtonItem
in your viewController.The documentation says that you should only pass
NO
before the nav controller's view is displayed.Remember that applications that do not conform to the iPhone Interface Guidelines will not be accepted into the app store.
我刚刚回答了另一个相关问题,该问题描述了如何轻松创建可复制的自定义后退按钮标准 iOS (iPhone / iPad) UI 后栏按钮项目的外观,但允许添加其他功能。根据 falconcreek 的回答中的建议,在
backButtonPressed
方法中,只需添加:I just answered another related question that describes how to easily create a custom back button that replicates the look of the standard iOS (iPhone / iPad) UI back bar button item but allows other functions to be added. As recommended in falconcreek's answer, in the
backButtonPressed
method, just add: