CCMainTabBarController.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // CCMainTabBarController.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 30/03/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. import Foundation
  9. class CCMainTabBarController : UITabBarController, UITabBarControllerDelegate {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. delegate = self
  13. }
  14. //Delegate methods
  15. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  16. let tabViewControllers = tabBarController.viewControllers!
  17. let fromView = tabBarController.selectedViewController!.view
  18. let toView = viewController.view
  19. if (fromView == toView) {
  20. return false
  21. }
  22. let fromIndex = tabViewControllers.index(of: tabBarController.selectedViewController!)
  23. let toIndex = tabViewControllers.index(of: viewController)
  24. let offScreenRight = CGAffineTransform(translationX: (toView?.frame.width)!, y: 0)
  25. let offScreenLeft = CGAffineTransform(translationX: -(toView?.frame.width)!, y: 0)
  26. // start the toView to the right of the screen
  27. if (toIndex! < fromIndex!) {
  28. toView?.transform = offScreenLeft
  29. fromView?.transform = offScreenRight
  30. } else {
  31. toView?.transform = offScreenRight
  32. fromView?.transform = offScreenLeft
  33. }
  34. fromView?.tag = 124
  35. toView?.addSubview(fromView!)
  36. self.view.isUserInteractionEnabled = false
  37. UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
  38. toView?.transform = CGAffineTransform.identity
  39. }, completion: { finished in
  40. let subViews = toView?.subviews
  41. for subview in subViews!{
  42. if (subview.tag == 124) {
  43. subview.removeFromSuperview()
  44. }
  45. }
  46. tabBarController.selectedIndex = toIndex!
  47. self.view.isUserInteractionEnabled = true
  48. })
  49. return true
  50. }
  51. }