CCMainTabBarController.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // CCMainTabBarController.swift
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 30/03/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class CCMainTabBarController : UITabBarController, UITabBarControllerDelegate {
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. delegate = self
  28. }
  29. //Delegate methods
  30. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  31. let tabViewControllers = tabBarController.viewControllers!
  32. let fromView = tabBarController.selectedViewController!.view
  33. let toView = viewController.view
  34. if (fromView == toView) {
  35. return false
  36. }
  37. let fromIndex = tabViewControllers.index(of: tabBarController.selectedViewController!)
  38. let toIndex = tabViewControllers.index(of: viewController)
  39. let offScreenRight = CGAffineTransform(translationX: (toView?.frame.width)!, y: 0)
  40. let offScreenLeft = CGAffineTransform(translationX: -(toView?.frame.width)!, y: 0)
  41. // start the toView to the right of the screen
  42. if (toIndex! < fromIndex!) {
  43. toView?.transform = offScreenLeft
  44. fromView?.transform = offScreenRight
  45. } else {
  46. toView?.transform = offScreenRight
  47. fromView?.transform = offScreenLeft
  48. }
  49. fromView?.tag = 124
  50. toView?.addSubview(fromView!)
  51. self.view.isUserInteractionEnabled = false
  52. UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
  53. toView?.transform = CGAffineTransform.identity
  54. }, completion: { finished in
  55. let subViews = toView?.subviews
  56. for subview in subViews!{
  57. if (subview.tag == 124) {
  58. subview.removeFromSuperview()
  59. }
  60. }
  61. tabBarController.selectedIndex = toIndex!
  62. self.view.isUserInteractionEnabled = true
  63. })
  64. return true
  65. }
  66. }