diff options
author | marinofaggiana <marino@marinofaggiana.com> | 2020-09-26 15:20:07 +0300 |
---|---|---|
committer | marinofaggiana <marino@marinofaggiana.com> | 2020-09-26 15:20:07 +0300 |
commit | 0ccbf2b5347ba3f84db7b3265b8a29a168d2a0b1 (patch) | |
tree | 05bf4e581ae54089d44d432241f278ab05bdce36 | |
parent | 84a124147c16d9a9c90660e4a361d7f04587f3a9 (diff) |
coding
-rwxr-xr-x | Nextcloud.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | iOSClient/Main/Main.storyboard | 2 | ||||
-rw-r--r-- | iOSClient/Main/NCMainCommon.swift | 64 | ||||
-rw-r--r-- | iOSClient/Main/NCMainTabBarController.swift | 88 |
4 files changed, 93 insertions, 65 deletions
diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index ee2ec8f96..2f7e77f97 100755 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -302,6 +302,7 @@ F7E0E1DC22327885006B0911 /* NCAudioRecorderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7E0E1DB22327885006B0911 /* NCAudioRecorderViewController.swift */; }; F7E0E1DE22327DBA006B0911 /* NCAudioRecorderViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7E0E1DD22327DBA006B0911 /* NCAudioRecorderViewController.storyboard */; }; F7E4D9C422ED929B003675FD /* NCShareComments.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7E4D9C322ED929B003675FD /* NCShareComments.swift */; }; + F7ECFB7E251F67E500EDBC17 /* NCMainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7ECFB7D251F67E500EDBC17 /* NCMainTabBarController.swift */; }; F7F1E54C2492369A00E42386 /* NCMediaCommandView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7F1E54B2492369A00E42386 /* NCMediaCommandView.xib */; }; F7F4B1D823C74B3E00D82A6E /* NCRichWorkspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4B1D723C74B3E00D82A6E /* NCRichWorkspace.swift */; }; F7F878AE1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */; }; @@ -715,6 +716,7 @@ F7E45E6D21E75BF200579249 /* ja-JP */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ja-JP"; path = "ja-JP.lproj/Localizable.strings"; sourceTree = "<group>"; }; F7E4D9C322ED929B003675FD /* NCShareComments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareComments.swift; sourceTree = "<group>"; }; F7E856182351D7BE009A3330 /* SwiftyXMLParser.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyXMLParser.framework; path = Carthage/Build/iOS/SwiftyXMLParser.framework; sourceTree = "<group>"; }; + F7ECFB7D251F67E500EDBC17 /* NCMainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMainTabBarController.swift; sourceTree = "<group>"; }; F7F0617A1BAACDD300846525 /* CryptoCloud.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoCloud.pch; sourceTree = "<group>"; }; F7F1E54B2492369A00E42386 /* NCMediaCommandView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMediaCommandView.xib; sourceTree = "<group>"; }; F7F4B1D723C74B3E00D82A6E /* NCRichWorkspace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCRichWorkspace.swift; sourceTree = "<group>"; }; @@ -841,6 +843,7 @@ F7226EDB1EE4089300EBECB1 /* Main.storyboard */, F710D1F624057C9400A6033D /* NCDetailNavigationController.swift */, 37C83A0C24532B7200618A3B /* AppDelegate+Swift.swift */, + F7ECFB7D251F67E500EDBC17 /* NCMainTabBarController.swift */, 37C83A0E24532BA600618A3B /* CCMain+Swift.swift */, F710D1F824057C9D00A6033D /* NCDetailViewController.swift */, F7D6650620FF341600BFBA9E /* NCMainCommon.swift */, @@ -2129,6 +2132,7 @@ F745B253222D88AE00346520 /* NCLoginQRCode.swift in Sources */, F7CBC31C24F78E79004D3812 /* NCSortMenu.swift in Sources */, F7169A1C1EE590930086BD69 /* NCShares.m in Sources */, + F7ECFB7E251F67E500EDBC17 /* NCMainTabBarController.swift in Sources */, F769454822E9F20D000A798A /* NCShareNetworking.swift in Sources */, F7C9555521F0C5470024296E /* NCActivity.swift in Sources */, F7725A60251F33BB00D125E0 /* NCFiles.swift in Sources */, diff --git a/iOSClient/Main/Main.storyboard b/iOSClient/Main/Main.storyboard index 22f7d1159..f120b98fb 100644 --- a/iOSClient/Main/Main.storyboard +++ b/iOSClient/Main/Main.storyboard @@ -132,7 +132,7 @@ <!--Main Tab Bar Controller--> <scene sceneID="gY3-Ur-rTC"> <objects> - <tabBarController extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="FkP-Lh-8zt" customClass="CCMainTabBarController" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController"> + <tabBarController extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="FkP-Lh-8zt" customClass="NCMainTabBarController" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController"> <toolbarItems/> <navigationItem key="navigationItem" id="ozb-fg-0GE"> <barButtonItem key="backBarButtonItem" title="Back" id="oUu-2v-gUF"/> diff --git a/iOSClient/Main/NCMainCommon.swift b/iOSClient/Main/NCMainCommon.swift index 171a1c532..93b77c6fe 100644 --- a/iOSClient/Main/NCMainCommon.swift +++ b/iOSClient/Main/NCMainCommon.swift @@ -453,68 +453,4 @@ class NCMainCommon: NSObject { } -//MARK: - Main TabBarController -class CCMainTabBarController : UITabBarController, UITabBarControllerDelegate { - - override func viewDidLoad() { - - super.viewDidLoad() - delegate = self - } - - //Delegate methods - func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { - - let tabViewControllers = tabBarController.viewControllers! - guard let toIndex = tabViewControllers.firstIndex(of: viewController) else { - - if let vc = viewController as? UINavigationController { - vc.popToRootViewController(animated: true); - } - - return false - } - - animateToTab(toIndex: toIndex) - - return true - } - - func animateToTab(toIndex: Int) { - - let tabViewControllers = viewControllers! - let fromView = selectedViewController!.view! - let toView = tabViewControllers[toIndex].view! - let fromIndex = tabViewControllers.firstIndex(of: selectedViewController!) - - guard fromIndex != toIndex else {return} - - // Add the toView to the tab bar view - fromView.superview?.addSubview(toView) - fromView.superview?.backgroundColor = NCBrandColor.sharedInstance.backgroundView - - // Position toView off screen (to the left/right of fromView) - let screenWidth = UIScreen.main.bounds.size.width; - let scrollRight = toIndex > fromIndex!; - let offset = (scrollRight ? screenWidth : -screenWidth) - toView.center = CGPoint(x: (fromView.center.x) + offset, y: (toView.center.y)) - - // Disable interaction during animation - view.isUserInteractionEnabled = false - - UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: UIView.AnimationOptions.curveEaseOut, animations: { - - // Slide the views by -offset - fromView.center = CGPoint(x: fromView.center.x - offset, y: fromView.center.y); - toView.center = CGPoint(x: toView.center.x - offset, y: toView.center.y); - - }, completion: { finished in - - // Remove the old view from the tabbar view. - fromView.removeFromSuperview() - self.selectedIndex = toIndex - self.view.isUserInteractionEnabled = true - }) - } -} diff --git a/iOSClient/Main/NCMainTabBarController.swift b/iOSClient/Main/NCMainTabBarController.swift new file mode 100644 index 000000000..fa6d4ddc3 --- /dev/null +++ b/iOSClient/Main/NCMainTabBarController.swift @@ -0,0 +1,88 @@ +// +// NCMainTabBarController.swift +// Nextcloud +// +// Created by Marino Faggiana on 26/09/2020. +// Copyright © 2020 Marino Faggiana. All rights reserved. +// +// Author Marino Faggiana <marino.faggiana@nextcloud.com> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +import Foundation + +class NCMainTabBarController : UITabBarController, UITabBarControllerDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + + delegate = self + } + + //Delegate methods + func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { + + let tabViewControllers = tabBarController.viewControllers! + guard let toIndex = tabViewControllers.firstIndex(of: viewController) else { + + if let vc = viewController as? UINavigationController { + vc.popToRootViewController(animated: true); + } + + return false + } + + animateToTab(toIndex: toIndex) + + return true + } + + func animateToTab(toIndex: Int) { + + let tabViewControllers = viewControllers! + let fromView = selectedViewController!.view! + let toView = tabViewControllers[toIndex].view! + let fromIndex = tabViewControllers.firstIndex(of: selectedViewController!) + + guard fromIndex != toIndex else {return} + + // Add the toView to the tab bar view + fromView.superview?.addSubview(toView) + fromView.superview?.backgroundColor = NCBrandColor.sharedInstance.backgroundView + + // Position toView off screen (to the left/right of fromView) + let screenWidth = UIScreen.main.bounds.size.width; + let scrollRight = toIndex > fromIndex!; + let offset = (scrollRight ? screenWidth : -screenWidth) + toView.center = CGPoint(x: (fromView.center.x) + offset, y: (toView.center.y)) + + // Disable interaction during animation + view.isUserInteractionEnabled = false + + UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: UIView.AnimationOptions.curveEaseOut, animations: { + + // Slide the views by -offset + fromView.center = CGPoint(x: fromView.center.x - offset, y: fromView.center.y); + toView.center = CGPoint(x: toView.center.x - offset, y: toView.center.y); + + }, completion: { finished in + + // Remove the old view from the tabbar view. + fromView.removeFromSuperview() + self.selectedIndex = toIndex + self.view.isUserInteractionEnabled = true + }) + } +} |