我正在使用包含三个视图控制器的页面视图控制器,其中一个视图控制器有一个按钮,我在其上使用推送视图来呈现来自右侧的另一个视图。每件事情都很好,视图是动画和呈现的。但问题是在uipageview控制器中的视图上呈现新视图,向右滑动呈现第二页面视图。我想使用转换作为单独的视图打开新视图。所以我想把它称为root vie解决了我猜的问题
这是我的代码
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : drawer = storyboard.instantiateViewControllerWithIdentifier("drawerID") as! drawer
hidesBottomBarWhenPushed = true
let transition: CATransition = CATransition()
let timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.duration = 0.25
transition.timingFunction = timeFunc
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight //kCATransitionFromLeft
self.navigationController!.view.layer.addAnimation(transition, forKey: kCATransition)
self.navigationController!.pushViewController(vc, animated: false)
修改后的代码
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : drawer = storyboard.instantiateViewControllerWithIdentifier("drawerID") as! drawer
var nav = appDelegate.window?.rootViewController as? UINavigationController
nav = UINavigationController.init(rootViewController:vc )
hidesBottomBarWhenPushed = true
let transition: CATransition = CATransition()
let timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.duration = 0.25
transition.timingFunction = timeFunc
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight //kCATransitionFromLeft
nav!.view.layer.addAnimation(transition, forKey: kCATransition)
appDelegate.window?.rootViewController = nav
appDelegate.window?.makeKeyAndVisible()
答案 0 :(得分:2)
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewControllerWithIdentifier("drawer")
appDelegate.navigationController = UINavigationController.init(rootViewController:initialViewController )
appDelegate.navigationController?.setViewControllers([initialViewController], animated: false)
appDelegate.window?.rootViewController = appDelegate.navigationController
appDelegate.window?.makeKeyAndVisible()