Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. class func animateToVC(sender: UIViewController, destination: UITabBarController, index: Int) {
  2.  
  3. let fromView = sender.view
  4. destination.selectedIndex = index
  5. let toView = destination.view
  6.  
  7. // Add the toView to fromView view
  8. fromView?.superview!.addSubview(toView!)
  9.  
  10. // Position toView off screen (to the left/right of fromView)
  11. let screenHeight = UIScreen.main.bounds.size.height
  12.  
  13. let offset = (screenHeight : -screenHeight)
  14.  
  15. toView?.center = CGPoint(x: (fromView?.center.x)!, y: (toView?.center.y)! + offset)
  16.  
  17. // Disable interaction during animation
  18. toView?.isUserInteractionEnabled = false
  19.  
  20. UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.7, options: UIViewAnimationOptions.curveEaseOut, animations: {
  21.  
  22. // Slide the views by -offset
  23. fromView?.center = CGPoint(x: (fromView?.center.x)!, y: (fromView?.center.y)! - offset)
  24. toView?.center = CGPoint(x: (toView?.center.x)!, y: (toView?.center.y)! - offset)
  25.  
  26. }, completion: { finished in
  27.  
  28. // Remove the old view.
  29. fromView?.removeFromSuperview()
  30.  
  31. // Re-enable interaction after animation
  32. toView?.isUserInteractionEnabled = true
  33. })
  34. }
  35.  
  36. let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
  37.  
  38. ViewControllerTransition.animateToVC(sender: self, destination: tbc, index: 1)
  39.  
  40. let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
  41. tbc.modalTransitionStyle = .coverVertical
  42. self.present(tbc, animated: true, completion: nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement