swift中tabbar切换页面动画

来源:互联网 发布:数据分析师需要学什么 编辑:程序博客网 时间:2024/06/05 07:12

1、直接通过UITabbarController.selectedindex = 1跳转页面的话,可以用下面的方法实现跳转后动画页面

var selectedViewController = UITabbarController.selectedViewController

        var animation =CATransition()

        animation.duration =0.5

        animation.type =kCATransitionPush//动画样式,有多种

        animation.subtype =kCATransitionFromLeft

        animation.timingFunction =CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseOut)

        selectedViewController.view.layer.addAnimation(animation, forKey:"switchView")//添加动画


2、点击tabbar切换页面,可以在UITabBarControllerDelegate的实现方法didSelectViewController中添加动画

func tabBarController(tabBarController:UITabBarController, didSelectViewController viewController:UIViewController) {

            var animation =CATransition()

            animation.duration =0.5

            animation.type =kCATransitionPush

            animation.subtype =kCATransitionFromLeft

            animation.timingFunction =CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseOut)

            viewController.view.layer.addAnimation(animation, forKey:"switchView")        

    }




0 1
原创粉丝点击