TechChain
TechChain

Reputation: 8944

Slide animation with UIView Transition?

I am setting a new navigation root. I want to show the animation when navigation is set. I am able to set the flip & curl animation with below code.

UIView.transition(with: self.window!, duration: 2, options: .transitionFlipFromLeft, animations: {
    let navController = UINavigationController()
    // App Theming
    navController.navigationBar.barTintColor = .white
    navController.navigationBar.tintColor = .white
    navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    navController.pushViewController(viewContoller, animated: true)
    self.window?.rootViewController = navController
    self.window?.makeKeyAndVisible()
}, completion: {_ in})

But, I need to set a slide animation from left to right for this. Can any body let me know how can I achieve this?

Upvotes: 1

Views: 510

Answers (1)

agibson007
agibson007

Reputation: 4373

If you want to fake a push on a new root view you could do something like this.

    let navController = UINavigationController()
    //App Theming
    navController.navigationBar.barTintColor = .white
    navController.navigationBar.tintColor = .white
    navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    //create our fake animation
    let trans = CATransition()
    trans.type = kCATransitionPush
    trans.subtype = kCATransitionFromRight
    trans.duration = 0.4
    self.window?.layer.add(trans, forKey: nil)
    //set your window change here
    self.window?.rootViewController = navController
    self.window?.makeKeyAndVisible()

Completely untested but I am pretty sure I have done this in the past at some point. If that does not work try setting the rootViewController then adding the animation.

Upvotes: 1

Related Questions