swift中tabbar切换页面动画

前端之家收集整理的这篇文章主要介绍了swift中tabbar切换页面动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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")

}

原文链接:https://www.f2er.com/swift/326377.html

猜你在找的Swift相关文章