Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class func animateToVC(sender: UIViewController, destination: UITabBarController, index: Int) {
- let fromView = sender.view
- destination.selectedIndex = index
- let toView = destination.view
- // Add the toView to fromView view
- fromView?.superview!.addSubview(toView!)
- // Position toView off screen (to the left/right of fromView)
- let screenHeight = UIScreen.main.bounds.size.height
- let offset = (screenHeight : -screenHeight)
- toView?.center = CGPoint(x: (fromView?.center.x)!, y: (toView?.center.y)! + offset)
- // Disable interaction during animation
- toView?.isUserInteractionEnabled = false
- UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.7, options: UIViewAnimationOptions.curveEaseOut, animations: {
- // Slide the views by -offset
- fromView?.center = CGPoint(x: (fromView?.center.x)!, y: (fromView?.center.y)! - offset)
- toView?.center = CGPoint(x: (toView?.center.x)!, y: (toView?.center.y)! - offset)
- }, completion: { finished in
- // Remove the old view.
- fromView?.removeFromSuperview()
- // Re-enable interaction after animation
- toView?.isUserInteractionEnabled = true
- })
- }
- let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
- ViewControllerTransition.animateToVC(sender: self, destination: tbc, index: 1)
- let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
- tbc.modalTransitionStyle = .coverVertical
- self.present(tbc, animated: true, completion: nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement