├── .gitignore ├── LICENSE ├── LxTabBarController.swift ├── LxTabBarControllerDemo ├── LxTabBarControllerDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── LxTabBarControllerDemo │ ├── AppDelegate.swift │ ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard │ ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift ├── README.md └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /LxTabBarController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LxTabBarController.swift 3 | // LxTabBarControllerDemo 4 | // 5 | 6 | import UIKit 7 | 8 | enum LxTabBarControllerInteractionStopReason { 9 | 10 | case Finished, Cancelled, Failed 11 | } 12 | 13 | let LxTabBarControllerDidSelectViewControllerNotification = "LxTabBarControllerDidSelectViewControllerNotification" 14 | 15 | private enum LxTabBarControllerSwitchType { 16 | 17 | case Unknown, Last, Next 18 | } 19 | 20 | let TRANSITION_DURATION = 0.2 21 | private var _switchType = LxTabBarControllerSwitchType.Unknown 22 | 23 | class Transition: NSObject, UIViewControllerAnimatedTransitioning { 24 | 25 | func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { 26 | return TRANSITION_DURATION 27 | } 28 | 29 | func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 30 | 31 | let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)! 32 | let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! 33 | 34 | transitionContext.containerView().insertSubview(toViewController.view, aboveSubview: fromViewController.view) 35 | 36 | switch _switchType { 37 | 38 | case .Last: 39 | toViewController.view.frame.origin.x = -toViewController.view.frame.size.width 40 | case .Next: 41 | toViewController.view.frame.origin.x = toViewController.view.frame.size.width 42 | case .Unknown: 43 | break 44 | } 45 | 46 | UIView.animateWithDuration(TRANSITION_DURATION, animations: { () -> Void in 47 | 48 | switch _switchType { 49 | 50 | case .Last: 51 | fromViewController.view.frame.origin.x = fromViewController.view.frame.size.width 52 | case .Next: 53 | fromViewController.view.frame.origin.x = -fromViewController.view.frame.size.width 54 | case .Unknown: 55 | break 56 | } 57 | toViewController.view.frame = transitionContext.containerView().bounds 58 | 59 | }) { (finished) -> Void in 60 | transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) 61 | } 62 | } 63 | } 64 | 65 | class LxTabBarController: UITabBarController,UITabBarControllerDelegate,UIGestureRecognizerDelegate { 66 | 67 | var panToSwitchGestureRecognizerEnabled: Bool { 68 | 69 | get { 70 | return _panToSwitchGestureRecognizer.enabled 71 | } 72 | set { 73 | _panToSwitchGestureRecognizer.enabled = newValue 74 | } 75 | } 76 | 77 | var recognizeOtherGestureSimultaneously = false 78 | var isTranslating = false 79 | var panGestureRecognizerBeginBlock = { () -> Void in } 80 | var panGestureRecognizerStopBlock = { (stopReason: LxTabBarControllerInteractionStopReason) -> Void in } 81 | 82 | let _panToSwitchGestureRecognizer = UIPanGestureRecognizer() 83 | var _interactiveTransition: UIPercentDrivenInteractiveTransition? 84 | 85 | convenience init () { 86 | self.init(nibName: nil, bundle: nil) 87 | setup() 88 | } 89 | 90 | required init(coder aDecoder: NSCoder) { 91 | super.init(coder: aDecoder) 92 | setup() 93 | } 94 | 95 | override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { 96 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) 97 | // setup() 98 | } 99 | 100 | func setup() { 101 | 102 | self.delegate = self 103 | 104 | _panToSwitchGestureRecognizer.addTarget(self, action: "panGestureRecognizerTriggerd:") 105 | _panToSwitchGestureRecognizer.delegate = self 106 | _panToSwitchGestureRecognizer.cancelsTouchesInView = false 107 | _panToSwitchGestureRecognizer.maximumNumberOfTouches = 1 108 | view.addGestureRecognizer(_panToSwitchGestureRecognizer) 109 | } 110 | 111 | func tabBarController(tabBarController: UITabBarController, interactionControllerForAnimationController animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { 112 | 113 | return animationController is Transition ? _interactiveTransition : nil 114 | } 115 | 116 | func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 117 | 118 | return Transition() 119 | } 120 | 121 | func panGestureRecognizerTriggerd(pan: UIPanGestureRecognizer) { 122 | 123 | var progress = pan.translationInView(pan.view!).x / pan.view!.bounds.size.width 124 | 125 | if progress > 0 { 126 | _switchType = .Last 127 | } 128 | else if progress < 0 { 129 | _switchType = .Next 130 | } 131 | else { 132 | _switchType = .Unknown 133 | } 134 | 135 | progress = abs(progress) 136 | progress = max(0, progress) 137 | progress = min(1, progress) 138 | 139 | switch pan.state { 140 | 141 | case .Began: 142 | isTranslating = true 143 | _interactiveTransition = UIPercentDrivenInteractiveTransition() 144 | switch _switchType { 145 | 146 | case .Last: 147 | selectedIndex = max(0, selectedIndex - 1) 148 | selectedViewController = viewControllers![selectedIndex] as? UIViewController 149 | panGestureRecognizerBeginBlock() 150 | case .Next: 151 | selectedIndex = min(viewControllers!.count, selectedIndex + 1) 152 | selectedViewController = viewControllers![selectedIndex] as? UIViewController 153 | panGestureRecognizerBeginBlock() 154 | case .Unknown: 155 | break 156 | } 157 | case .Changed: 158 | _interactiveTransition?.updateInteractiveTransition(CGFloat(progress)) 159 | case .Failed: 160 | isTranslating = false 161 | panGestureRecognizerStopBlock(.Failed) 162 | default: 163 | 164 | if abs(progress) > 0.5 { 165 | 166 | _interactiveTransition?.finishInteractiveTransition() 167 | panGestureRecognizerStopBlock(.Finished) 168 | } 169 | else { 170 | _interactiveTransition?.cancelInteractiveTransition() 171 | panGestureRecognizerStopBlock(.Cancelled) 172 | } 173 | 174 | _interactiveTransition = nil 175 | isTranslating = false 176 | } 177 | } 178 | 179 | func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool { 180 | 181 | if gestureRecognizer == _panToSwitchGestureRecognizer { 182 | 183 | return !isTranslating 184 | } 185 | else { 186 | return true 187 | } 188 | } 189 | 190 | func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { 191 | 192 | if gestureRecognizer == _panToSwitchGestureRecognizer || otherGestureRecognizer == _panToSwitchGestureRecognizer { 193 | 194 | return recognizeOtherGestureSimultaneously 195 | } 196 | else { 197 | return false 198 | } 199 | } 200 | 201 | func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool { 202 | 203 | let viewControllerIndex = find(tabBarController.viewControllers as! [UIViewController], viewController) 204 | 205 | if viewControllerIndex > selectedIndex { 206 | _switchType = .Next 207 | } 208 | else if viewControllerIndex < selectedIndex { 209 | _switchType = .Last 210 | } 211 | else { 212 | _switchType = .Unknown 213 | } 214 | return true 215 | } 216 | 217 | func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) { 218 | 219 | NSNotificationCenter.defaultCenter().postNotificationName(LxTabBarControllerDidSelectViewControllerNotification, object: nil) 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B639DB8F1B495ADD00DF6A81 /* LxTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B639DB8E1B495ADD00DF6A81 /* LxTabBarController.swift */; }; 11 | B6A91B381B482F2B0051B3DD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6A91B371B482F2B0051B3DD /* AppDelegate.swift */; }; 12 | B6A91B3A1B482F2B0051B3DD /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6A91B391B482F2B0051B3DD /* ViewController.swift */; }; 13 | B6A91B3D1B482F2B0051B3DD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B6A91B3B1B482F2B0051B3DD /* Main.storyboard */; }; 14 | B6A91B3F1B482F2B0051B3DD /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B6A91B3E1B482F2B0051B3DD /* Images.xcassets */; }; 15 | B6A91B421B482F2B0051B3DD /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = B6A91B401B482F2B0051B3DD /* LaunchScreen.xib */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | B639DB8E1B495ADD00DF6A81 /* LxTabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LxTabBarController.swift; path = ../../LxTabBarController.swift; sourceTree = ""; }; 20 | B6A91B321B482F2B0051B3DD /* LxTabBarControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LxTabBarControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | B6A91B361B482F2B0051B3DD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 22 | B6A91B371B482F2B0051B3DD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | B6A91B391B482F2B0051B3DD /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | B6A91B3C1B482F2B0051B3DD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | B6A91B3E1B482F2B0051B3DD /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 26 | B6A91B411B482F2B0051B3DD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | B6A91B2F1B482F2B0051B3DD /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | B6A91B291B482F2B0051B3DD = { 41 | isa = PBXGroup; 42 | children = ( 43 | B6A91B341B482F2B0051B3DD /* LxTabBarControllerDemo */, 44 | B6A91B331B482F2B0051B3DD /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | B6A91B331B482F2B0051B3DD /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | B6A91B321B482F2B0051B3DD /* LxTabBarControllerDemo.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | B6A91B341B482F2B0051B3DD /* LxTabBarControllerDemo */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | B639DB8E1B495ADD00DF6A81 /* LxTabBarController.swift */, 60 | B6A91B391B482F2B0051B3DD /* ViewController.swift */, 61 | B6A91B371B482F2B0051B3DD /* AppDelegate.swift */, 62 | B6A91B351B482F2B0051B3DD /* Supporting Files */, 63 | ); 64 | path = LxTabBarControllerDemo; 65 | sourceTree = ""; 66 | }; 67 | B6A91B351B482F2B0051B3DD /* Supporting Files */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | B6A91B401B482F2B0051B3DD /* LaunchScreen.xib */, 71 | B6A91B3B1B482F2B0051B3DD /* Main.storyboard */, 72 | B6A91B3E1B482F2B0051B3DD /* Images.xcassets */, 73 | B6A91B361B482F2B0051B3DD /* Info.plist */, 74 | ); 75 | name = "Supporting Files"; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | B6A91B311B482F2B0051B3DD /* LxTabBarControllerDemo */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = B6A91B511B482F2B0051B3DD /* Build configuration list for PBXNativeTarget "LxTabBarControllerDemo" */; 84 | buildPhases = ( 85 | B6A91B2E1B482F2B0051B3DD /* Sources */, 86 | B6A91B2F1B482F2B0051B3DD /* Frameworks */, 87 | B6A91B301B482F2B0051B3DD /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = LxTabBarControllerDemo; 94 | productName = LxTabBarControllerDemo; 95 | productReference = B6A91B321B482F2B0051B3DD /* LxTabBarControllerDemo.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | B6A91B2A1B482F2B0051B3DD /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastUpgradeCheck = 0630; 105 | ORGANIZATIONNAME = DeveloperLx; 106 | TargetAttributes = { 107 | B6A91B311B482F2B0051B3DD = { 108 | CreatedOnToolsVersion = 6.3; 109 | }; 110 | }; 111 | }; 112 | buildConfigurationList = B6A91B2D1B482F2B0051B3DD /* Build configuration list for PBXProject "LxTabBarControllerDemo" */; 113 | compatibilityVersion = "Xcode 3.2"; 114 | developmentRegion = English; 115 | hasScannedForEncodings = 0; 116 | knownRegions = ( 117 | en, 118 | Base, 119 | ); 120 | mainGroup = B6A91B291B482F2B0051B3DD; 121 | productRefGroup = B6A91B331B482F2B0051B3DD /* Products */; 122 | projectDirPath = ""; 123 | projectRoot = ""; 124 | targets = ( 125 | B6A91B311B482F2B0051B3DD /* LxTabBarControllerDemo */, 126 | ); 127 | }; 128 | /* End PBXProject section */ 129 | 130 | /* Begin PBXResourcesBuildPhase section */ 131 | B6A91B301B482F2B0051B3DD /* Resources */ = { 132 | isa = PBXResourcesBuildPhase; 133 | buildActionMask = 2147483647; 134 | files = ( 135 | B6A91B3D1B482F2B0051B3DD /* Main.storyboard in Resources */, 136 | B6A91B421B482F2B0051B3DD /* LaunchScreen.xib in Resources */, 137 | B6A91B3F1B482F2B0051B3DD /* Images.xcassets in Resources */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | /* End PBXResourcesBuildPhase section */ 142 | 143 | /* Begin PBXSourcesBuildPhase section */ 144 | B6A91B2E1B482F2B0051B3DD /* Sources */ = { 145 | isa = PBXSourcesBuildPhase; 146 | buildActionMask = 2147483647; 147 | files = ( 148 | B639DB8F1B495ADD00DF6A81 /* LxTabBarController.swift in Sources */, 149 | B6A91B3A1B482F2B0051B3DD /* ViewController.swift in Sources */, 150 | B6A91B381B482F2B0051B3DD /* AppDelegate.swift in Sources */, 151 | ); 152 | runOnlyForDeploymentPostprocessing = 0; 153 | }; 154 | /* End PBXSourcesBuildPhase section */ 155 | 156 | /* Begin PBXVariantGroup section */ 157 | B6A91B3B1B482F2B0051B3DD /* Main.storyboard */ = { 158 | isa = PBXVariantGroup; 159 | children = ( 160 | B6A91B3C1B482F2B0051B3DD /* Base */, 161 | ); 162 | name = Main.storyboard; 163 | sourceTree = ""; 164 | }; 165 | B6A91B401B482F2B0051B3DD /* LaunchScreen.xib */ = { 166 | isa = PBXVariantGroup; 167 | children = ( 168 | B6A91B411B482F2B0051B3DD /* Base */, 169 | ); 170 | name = LaunchScreen.xib; 171 | sourceTree = ""; 172 | }; 173 | /* End PBXVariantGroup section */ 174 | 175 | /* Begin XCBuildConfiguration section */ 176 | B6A91B4F1B482F2B0051B3DD /* Debug */ = { 177 | isa = XCBuildConfiguration; 178 | buildSettings = { 179 | ALWAYS_SEARCH_USER_PATHS = NO; 180 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 181 | CLANG_CXX_LIBRARY = "libc++"; 182 | CLANG_ENABLE_MODULES = YES; 183 | CLANG_ENABLE_OBJC_ARC = YES; 184 | CLANG_WARN_BOOL_CONVERSION = YES; 185 | CLANG_WARN_CONSTANT_CONVERSION = YES; 186 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 187 | CLANG_WARN_EMPTY_BODY = YES; 188 | CLANG_WARN_ENUM_CONVERSION = YES; 189 | CLANG_WARN_INT_CONVERSION = YES; 190 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 191 | CLANG_WARN_UNREACHABLE_CODE = YES; 192 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 193 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 194 | COPY_PHASE_STRIP = NO; 195 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 196 | ENABLE_STRICT_OBJC_MSGSEND = YES; 197 | GCC_C_LANGUAGE_STANDARD = gnu99; 198 | GCC_DYNAMIC_NO_PIC = NO; 199 | GCC_NO_COMMON_BLOCKS = YES; 200 | GCC_OPTIMIZATION_LEVEL = 0; 201 | GCC_PREPROCESSOR_DEFINITIONS = ( 202 | "DEBUG=1", 203 | "$(inherited)", 204 | ); 205 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 206 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 207 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 208 | GCC_WARN_UNDECLARED_SELECTOR = YES; 209 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 210 | GCC_WARN_UNUSED_FUNCTION = YES; 211 | GCC_WARN_UNUSED_VARIABLE = YES; 212 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 213 | MTL_ENABLE_DEBUG_INFO = YES; 214 | ONLY_ACTIVE_ARCH = YES; 215 | SDKROOT = iphoneos; 216 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 217 | TARGETED_DEVICE_FAMILY = "1,2"; 218 | }; 219 | name = Debug; 220 | }; 221 | B6A91B501B482F2B0051B3DD /* Release */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | ALWAYS_SEARCH_USER_PATHS = NO; 225 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 226 | CLANG_CXX_LIBRARY = "libc++"; 227 | CLANG_ENABLE_MODULES = YES; 228 | CLANG_ENABLE_OBJC_ARC = YES; 229 | CLANG_WARN_BOOL_CONVERSION = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 236 | CLANG_WARN_UNREACHABLE_CODE = YES; 237 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 238 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 239 | COPY_PHASE_STRIP = NO; 240 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 241 | ENABLE_NS_ASSERTIONS = NO; 242 | ENABLE_STRICT_OBJC_MSGSEND = YES; 243 | GCC_C_LANGUAGE_STANDARD = gnu99; 244 | GCC_NO_COMMON_BLOCKS = YES; 245 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 246 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 247 | GCC_WARN_UNDECLARED_SELECTOR = YES; 248 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 249 | GCC_WARN_UNUSED_FUNCTION = YES; 250 | GCC_WARN_UNUSED_VARIABLE = YES; 251 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 252 | MTL_ENABLE_DEBUG_INFO = NO; 253 | SDKROOT = iphoneos; 254 | TARGETED_DEVICE_FAMILY = "1,2"; 255 | VALIDATE_PRODUCT = YES; 256 | }; 257 | name = Release; 258 | }; 259 | B6A91B521B482F2B0051B3DD /* Debug */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 263 | INFOPLIST_FILE = LxTabBarControllerDemo/Info.plist; 264 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 265 | PRODUCT_NAME = "$(TARGET_NAME)"; 266 | }; 267 | name = Debug; 268 | }; 269 | B6A91B531B482F2B0051B3DD /* Release */ = { 270 | isa = XCBuildConfiguration; 271 | buildSettings = { 272 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 273 | INFOPLIST_FILE = LxTabBarControllerDemo/Info.plist; 274 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 275 | PRODUCT_NAME = "$(TARGET_NAME)"; 276 | }; 277 | name = Release; 278 | }; 279 | /* End XCBuildConfiguration section */ 280 | 281 | /* Begin XCConfigurationList section */ 282 | B6A91B2D1B482F2B0051B3DD /* Build configuration list for PBXProject "LxTabBarControllerDemo" */ = { 283 | isa = XCConfigurationList; 284 | buildConfigurations = ( 285 | B6A91B4F1B482F2B0051B3DD /* Debug */, 286 | B6A91B501B482F2B0051B3DD /* Release */, 287 | ); 288 | defaultConfigurationIsVisible = 0; 289 | defaultConfigurationName = Release; 290 | }; 291 | B6A91B511B482F2B0051B3DD /* Build configuration list for PBXNativeTarget "LxTabBarControllerDemo" */ = { 292 | isa = XCConfigurationList; 293 | buildConfigurations = ( 294 | B6A91B521B482F2B0051B3DD /* Debug */, 295 | B6A91B531B482F2B0051B3DD /* Release */, 296 | ); 297 | defaultConfigurationIsVisible = 0; 298 | defaultConfigurationName = Release; 299 | }; 300 | /* End XCConfigurationList section */ 301 | }; 302 | rootObject = B6A91B2A1B482F2B0051B3DD /* Project object */; 303 | } 304 | -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LxTabBarControllerDemo 4 | // 5 | 6 | import UIKit 7 | 8 | @UIApplicationMain 9 | class AppDelegate: UIResponder, UIApplicationDelegate { 10 | 11 | var window: UIWindow? 12 | 13 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 14 | 15 | let vc1 = ViewController() 16 | vc1.title = "vc1" 17 | let nc1 = UINavigationController(rootViewController: vc1) 18 | 19 | let vc2 = ViewController() 20 | vc2.title = "vc2" 21 | let nc2 = UINavigationController(rootViewController: vc2) 22 | 23 | let vc3 = ViewController() 24 | vc3.title = "vc3" 25 | let nc3 = UINavigationController(rootViewController: vc3) 26 | 27 | let vc4 = ViewController() 28 | vc4.title = "vc4" 29 | let nc4 = UINavigationController(rootViewController: vc4) 30 | 31 | let tabBarController = LxTabBarController() 32 | tabBarController.viewControllers = [nc1, nc2, nc3, nc4] 33 | window?.rootViewController = tabBarController 34 | 35 | return true 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | etiantian.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /LxTabBarControllerDemo/LxTabBarControllerDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LxTabBarControllerDemo 4 | // 5 | 6 | import UIKit 7 | 8 | class ViewController: UIViewController { 9 | 10 | convenience init() { 11 | 12 | self.init(nibName: nil, bundle: nil) 13 | 14 | tabBarItem = UITabBarItem(tabBarSystemItem: UITabBarSystemItem(rawValue: Int(arc4random())%12)!, tag: 0) 15 | title = tabBarItem.title 16 | } 17 | 18 | required init(coder aDecoder: NSCoder) { 19 | super.init(coder: aDecoder) 20 | } 21 | 22 | override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { 23 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) 24 | } 25 | 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | edgesForExtendedLayout = .None 30 | view.backgroundColor = UIColor(red: CGFloat(CGFloat(arc4random()) / 0xFFFFFFFF), green: CGFloat(CGFloat(arc4random()) / 0xFFFFFFFF), blue: CGFloat(CGFloat(arc4random()) / 0xFFFFFFFF), alpha: 1) 31 | 32 | let label = UILabel() 33 | label.text = "LxTabBarController " + "\(title!)" 34 | label.textColor = UIColor.whiteColor() 35 | label.textAlignment = .Center 36 | label.font = UIFont.boldSystemFontOfSize(27) 37 | view.addSubview(label) 38 | 39 | label.setTranslatesAutoresizingMaskIntoConstraints(false) 40 | 41 | let labelConstraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|-30-[label]-30-|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["label": label]) 42 | let labelConstraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:|-90-[label(==48)]", options: .DirectionLeadingToTrailing, metrics: nil, views: ["label": label]) 43 | 44 | view.addConstraints(labelConstraintsH) 45 | view.addConstraints(labelConstraintsV) 46 | } 47 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LxTabBarController-swift 2 | Inherited from UITabBarController. To change UITabBarController interactive mode, LxTabBarController add a powerful gesture you can switch view controller by sweeping screen from left the right or right to left. 3 | 4 | * ![demo](demo.gif) 5 | 6 | 7 | Installation 8 | ------------ 9 | You only need drag LxTabBarController.swift to your project. 10 | 11 | Support 12 | ------------ 13 | Minimum support iOS version: iOS 7.0 14 | 15 | Usage 16 | ---------- 17 | `Use LxTabBarController as same as UITabBarController.` 18 | 19 | let vc1 = ViewController() 20 | vc1.title = "vc1" 21 | let nc1 = UINavigationController(rootViewController: vc1) 22 | 23 | let vc2 = ViewController() 24 | vc2.title = "vc2" 25 | let nc2 = UINavigationController(rootViewController: vc2) 26 | 27 | let vc3 = ViewController() 28 | vc3.title = "vc3" 29 | let nc3 = UINavigationController(rootViewController: vc3) 30 | 31 | let vc4 = ViewController() 32 | vc4.title = "vc4" 33 | let nc4 = UINavigationController(rootViewController: vc4) 34 | 35 | let tabBarController = LxTabBarController() 36 | tabBarController.viewControllers = [nc1, nc2, nc3, nc4] 37 | 38 | BE CAREFUL! 39 | ----------- 40 | 41 | The gesture for switching tab has risk to cause conflict to other gestures, you can set tabBarController.panToSwitchGestureRecognizerEnabled = false to forbid it. 42 | 43 | License 44 | ----------- 45 | LxTabBarController is available under the Apache License 2.0. See the LICENSE file for more info. -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeveloperLx/LxTabBarController-swift/15ea27475ac30780e704d3a57efe00c0989f14a6/demo.gif --------------------------------------------------------------------------------