2

iOS原生UITabBarController添加视图切换动画

 1 year ago
source link: https://www.isaced.com/post-209.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

iOS原生UITabBarController添加视图切换动画

做完UINavigationController的Push动画后想到:怎么样在UITabBarController上也做一个切换动画?

以前包括很多时候都是通过自定义TabBarController来实现更多UI,和动画,可不可以使用原生的UITabBarController来做切换动画呢?(这里说的原生当然不包括从UITabBarController派生而来)

为什么能在UINavigationController做Push动画?因为我们能接收到Push、Pop的操作,或者说Push事件是我们自己发起的,这样就知道什么时候会切换视图。而UITabBarController稍稍有点不同,点击Tab的时候,如果没有自定义,我们在ViewController里是接收不到什么时候切换视图的响应,包括切换到哪个视图。

于是,想到通过ViewController的viewWillDisappear事件来给TabBarController的Layer添加一个CATransition,当然QuartzCore得添加并import。

-(void)viewWillDisappear:(BOOL)animated
{
    CATransition *transition = [CATransition animation];
    [transition setDuration:1];
    [transition setType:@"cube"];
    [self.tabBarController.view.layer addAnimation:transition forKey:nil];
}

这样的话,就算是点击Tab离开本视图控制器也会有动画,但是却接收不到即将去哪一个ViewController,从而无法做更复杂的东西。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK