简体   繁体   English

是否可以在切换视图时将动画插入到UITabBarController中?

[英]Is it possible to insert an animation into an UITabBarController thats shown when switching Views?

I have a custom UITabBarController and I want it to slide out the old view and slide in the new view whenever a TabBarItem gets pressed. 我有一个自定义的UITabBarController,我想让它在按下TabBarItem时滑出旧视图并在新视图中滑动。 I looked at UITabBarControllerDelegate but it just offers me to decide if the view gets displayed not how (via shouldSelectViewController). 我查看了UITabBarControllerDelegate,但它只是让我决定是否显示视图而不是如何显示(通过shouldSelectViewController)。 Is there a way to do that? 有没有办法做到这一点?

(My goal is to have a starfield background that looks almost the same on all the 4 views. It should look like the items get changed and the background just scrolls by a little) (我的目标是在所有4个视图中都有一个看起来几乎相同的星空背景。它应该看起来像项目变了,背景只是滚动了一点)

Subclass UITabBarController and make it it's own delegate. 子类UITabBarController并使其成为自己的委托。 Now you can intercept methods like tabBarController:shouldSelectViewController: and manipulate any custom views you have added to the tab bar. 现在,您可以拦截tabBarController:shouldSelectViewController:等方法,并操纵您添加到选项卡栏的任何自定义视图。 And if you add your starfield to the tab bar view, and then use tab controllers that have translucent views the common background can show through. 如果您将星空域添加到标签栏视图,然后使用具有半透明视图的标签控制器,则可以显示常见背景。

And you can even intercept tab bar controller methods directly like setSelectedIndex: to have even more control to let you fade things out. 您甚至可以直接拦截标签栏控制器方法,如setSelectedIndex:以获得更多控制权,让您淡出一些东西。 But just make sure that you call the super version of the method at some point if you do this so the tab bar remains functional. 但是,如果您这样做,请确保在某些时候调用方法的super版本,以便标签栏保持正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM