├── .gitignore ├── LICENSE ├── README.md ├── ScrollingTabBarDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── ScrollingTabBarDemo ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ScrollingTabBarUtils.swift └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | DerivedData 3 | 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 | *.xcuserstate 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Just contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScrollingTabBarControllerAnimation 2 | 3 | A horizontal scrolling animation for iOS `TabBarControllers`. Works with any number of `TabBarItems`, and any orientation. 4 | 5 | [Blog post](http://franklinsch.github.io/2015/12/25/scrolling-tab-bar.html) 6 | 7 | ## Demo 8 | 9 | With three `TabBarItems`: 10 | 11 | !["ScrollingTabBarControllerAnimation with three tabs"](demo.gif) 12 | 13 | ## Usage 14 | 15 | * Import `ScrollingTabBarUtils.swift` to your Xcode project 16 | * Set your `UITabBarController`'s `delegate` to `ScrollingTabBarControllerDelegate` 17 | 18 | Ex: 19 | 20 | class YourTabBarController: UITabBarController { 21 | 22 | let delegate = ScrollingTabBarControllerDelegate() 23 | 24 | override func viewDidLoad() { 25 | super.viewDidLoad() 26 | 27 | self.delegate = delegate 28 | } 29 | 30 | } 31 | 32 | * That's it! 33 | 34 | ## Customization 35 | 36 | The animation is provided by a call to `UIView.animateWithDuration(_:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)`, and the transition duration should be modified in `transitionDuration(_:)`. 37 | 38 | Feel free to modify these parameters. 39 | 40 | ## License 41 | 42 | MIT, see LICENSE for details. 43 | -------------------------------------------------------------------------------- /ScrollingTabBarDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 257B92FF1C2C426A0000FB6B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 257B92FE1C2C426A0000FB6B /* AppDelegate.swift */; }; 11 | 257B93041C2C426A0000FB6B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 257B93021C2C426A0000FB6B /* Main.storyboard */; }; 12 | 257B93061C2C426A0000FB6B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 257B93051C2C426A0000FB6B /* Assets.xcassets */; }; 13 | 257B93091C2C426A0000FB6B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 257B93071C2C426A0000FB6B /* LaunchScreen.storyboard */; }; 14 | 25CBCDE81C2C441700D9B6D9 /* ScrollingTabBarUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25CBCDE71C2C441700D9B6D9 /* ScrollingTabBarUtils.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 257B92FB1C2C426A0000FB6B /* ScrollingTabBarDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ScrollingTabBarDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 257B92FE1C2C426A0000FB6B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | 257B93031C2C426A0000FB6B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 21 | 257B93051C2C426A0000FB6B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | 257B93081C2C426A0000FB6B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 23 | 257B930A1C2C426A0000FB6B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 24 | 25CBCDE71C2C441700D9B6D9 /* ScrollingTabBarUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollingTabBarUtils.swift; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | 257B92F81C2C426A0000FB6B /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | 257B92F21C2C426A0000FB6B = { 39 | isa = PBXGroup; 40 | children = ( 41 | 257B92FD1C2C426A0000FB6B /* ScrollingTabBarDemo */, 42 | 257B92FC1C2C426A0000FB6B /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | 257B92FC1C2C426A0000FB6B /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 257B92FB1C2C426A0000FB6B /* ScrollingTabBarDemo.app */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 257B92FD1C2C426A0000FB6B /* ScrollingTabBarDemo */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 257B92FE1C2C426A0000FB6B /* AppDelegate.swift */, 58 | 25CBCDE71C2C441700D9B6D9 /* ScrollingTabBarUtils.swift */, 59 | 257B93021C2C426A0000FB6B /* Main.storyboard */, 60 | 257B93051C2C426A0000FB6B /* Assets.xcassets */, 61 | 257B93071C2C426A0000FB6B /* LaunchScreen.storyboard */, 62 | 257B930A1C2C426A0000FB6B /* Info.plist */, 63 | ); 64 | path = ScrollingTabBarDemo; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | 257B92FA1C2C426A0000FB6B /* ScrollingTabBarDemo */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = 257B93231C2C426B0000FB6B /* Build configuration list for PBXNativeTarget "ScrollingTabBarDemo" */; 73 | buildPhases = ( 74 | 257B92F71C2C426A0000FB6B /* Sources */, 75 | 257B92F81C2C426A0000FB6B /* Frameworks */, 76 | 257B92F91C2C426A0000FB6B /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = ScrollingTabBarDemo; 83 | productName = AnimatedTabBar; 84 | productReference = 257B92FB1C2C426A0000FB6B /* ScrollingTabBarDemo.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 257B92F31C2C426A0000FB6B /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastSwiftUpdateCheck = 0720; 94 | LastUpgradeCheck = 0900; 95 | ORGANIZATIONNAME = "Franklin Schrans"; 96 | TargetAttributes = { 97 | 257B92FA1C2C426A0000FB6B = { 98 | CreatedOnToolsVersion = 7.2; 99 | LastSwiftMigration = 0900; 100 | }; 101 | }; 102 | }; 103 | buildConfigurationList = 257B92F61C2C426A0000FB6B /* Build configuration list for PBXProject "ScrollingTabBarDemo" */; 104 | compatibilityVersion = "Xcode 3.2"; 105 | developmentRegion = English; 106 | hasScannedForEncodings = 0; 107 | knownRegions = ( 108 | en, 109 | Base, 110 | ); 111 | mainGroup = 257B92F21C2C426A0000FB6B; 112 | productRefGroup = 257B92FC1C2C426A0000FB6B /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | 257B92FA1C2C426A0000FB6B /* ScrollingTabBarDemo */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXResourcesBuildPhase section */ 122 | 257B92F91C2C426A0000FB6B /* Resources */ = { 123 | isa = PBXResourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | 257B93091C2C426A0000FB6B /* LaunchScreen.storyboard in Resources */, 127 | 257B93061C2C426A0000FB6B /* Assets.xcassets in Resources */, 128 | 257B93041C2C426A0000FB6B /* Main.storyboard in Resources */, 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | /* End PBXResourcesBuildPhase section */ 133 | 134 | /* Begin PBXSourcesBuildPhase section */ 135 | 257B92F71C2C426A0000FB6B /* Sources */ = { 136 | isa = PBXSourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 25CBCDE81C2C441700D9B6D9 /* ScrollingTabBarUtils.swift in Sources */, 140 | 257B92FF1C2C426A0000FB6B /* AppDelegate.swift in Sources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXSourcesBuildPhase section */ 145 | 146 | /* Begin PBXVariantGroup section */ 147 | 257B93021C2C426A0000FB6B /* Main.storyboard */ = { 148 | isa = PBXVariantGroup; 149 | children = ( 150 | 257B93031C2C426A0000FB6B /* Base */, 151 | ); 152 | name = Main.storyboard; 153 | sourceTree = ""; 154 | }; 155 | 257B93071C2C426A0000FB6B /* LaunchScreen.storyboard */ = { 156 | isa = PBXVariantGroup; 157 | children = ( 158 | 257B93081C2C426A0000FB6B /* Base */, 159 | ); 160 | name = LaunchScreen.storyboard; 161 | sourceTree = ""; 162 | }; 163 | /* End PBXVariantGroup section */ 164 | 165 | /* Begin XCBuildConfiguration section */ 166 | 257B93211C2C426B0000FB6B /* Debug */ = { 167 | isa = XCBuildConfiguration; 168 | buildSettings = { 169 | ALWAYS_SEARCH_USER_PATHS = NO; 170 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 171 | CLANG_CXX_LIBRARY = "libc++"; 172 | CLANG_ENABLE_MODULES = YES; 173 | CLANG_ENABLE_OBJC_ARC = YES; 174 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 175 | CLANG_WARN_BOOL_CONVERSION = YES; 176 | CLANG_WARN_COMMA = YES; 177 | CLANG_WARN_CONSTANT_CONVERSION = YES; 178 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 179 | CLANG_WARN_EMPTY_BODY = YES; 180 | CLANG_WARN_ENUM_CONVERSION = YES; 181 | CLANG_WARN_INFINITE_RECURSION = YES; 182 | CLANG_WARN_INT_CONVERSION = YES; 183 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 184 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 185 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 186 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 187 | CLANG_WARN_STRICT_PROTOTYPES = YES; 188 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 189 | CLANG_WARN_UNREACHABLE_CODE = YES; 190 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 191 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 192 | COPY_PHASE_STRIP = NO; 193 | DEBUG_INFORMATION_FORMAT = dwarf; 194 | ENABLE_STRICT_OBJC_MSGSEND = YES; 195 | ENABLE_TESTABILITY = YES; 196 | GCC_C_LANGUAGE_STANDARD = gnu99; 197 | GCC_DYNAMIC_NO_PIC = NO; 198 | GCC_NO_COMMON_BLOCKS = YES; 199 | GCC_OPTIMIZATION_LEVEL = 0; 200 | GCC_PREPROCESSOR_DEFINITIONS = ( 201 | "DEBUG=1", 202 | "$(inherited)", 203 | ); 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | INFOPLIST_FILE = "$(SRCROOT)/ScrollingTabBarDemo/Info.plist"; 211 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 212 | MTL_ENABLE_DEBUG_INFO = YES; 213 | ONLY_ACTIVE_ARCH = YES; 214 | SDKROOT = iphoneos; 215 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 216 | }; 217 | name = Debug; 218 | }; 219 | 257B93221C2C426B0000FB6B /* Release */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 224 | CLANG_CXX_LIBRARY = "libc++"; 225 | CLANG_ENABLE_MODULES = YES; 226 | CLANG_ENABLE_OBJC_ARC = YES; 227 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_COMMA = 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_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 237 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 240 | CLANG_WARN_STRICT_PROTOTYPES = YES; 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 242 | CLANG_WARN_UNREACHABLE_CODE = YES; 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 244 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 245 | COPY_PHASE_STRIP = NO; 246 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 247 | ENABLE_NS_ASSERTIONS = NO; 248 | ENABLE_STRICT_OBJC_MSGSEND = YES; 249 | GCC_C_LANGUAGE_STANDARD = gnu99; 250 | GCC_NO_COMMON_BLOCKS = YES; 251 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 252 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 253 | GCC_WARN_UNDECLARED_SELECTOR = YES; 254 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 255 | GCC_WARN_UNUSED_FUNCTION = YES; 256 | GCC_WARN_UNUSED_VARIABLE = YES; 257 | INFOPLIST_FILE = "$(SRCROOT)/ScrollingTabBarDemo/Info.plist"; 258 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 259 | MTL_ENABLE_DEBUG_INFO = NO; 260 | SDKROOT = iphoneos; 261 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 262 | VALIDATE_PRODUCT = YES; 263 | }; 264 | name = Release; 265 | }; 266 | 257B93241C2C426B0000FB6B /* Debug */ = { 267 | isa = XCBuildConfiguration; 268 | buildSettings = { 269 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 270 | DEVELOPMENT_TEAM = ""; 271 | INFOPLIST_FILE = "$(SRCROOT)/ScrollingTabBarDemo/Info.plist"; 272 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 273 | PRODUCT_BUNDLE_IDENTIFIER = com.franklinschrans.com.AnimatedTabBar; 274 | PRODUCT_NAME = ScrollingTabBarDemo; 275 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 276 | SWIFT_VERSION = 4.0; 277 | }; 278 | name = Debug; 279 | }; 280 | 257B93251C2C426B0000FB6B /* Release */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 284 | DEVELOPMENT_TEAM = ""; 285 | INFOPLIST_FILE = "$(SRCROOT)/ScrollingTabBarDemo/Info.plist"; 286 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 287 | PRODUCT_BUNDLE_IDENTIFIER = com.franklinschrans.com.AnimatedTabBar; 288 | PRODUCT_NAME = ScrollingTabBarDemo; 289 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 290 | SWIFT_VERSION = 4.0; 291 | }; 292 | name = Release; 293 | }; 294 | /* End XCBuildConfiguration section */ 295 | 296 | /* Begin XCConfigurationList section */ 297 | 257B92F61C2C426A0000FB6B /* Build configuration list for PBXProject "ScrollingTabBarDemo" */ = { 298 | isa = XCConfigurationList; 299 | buildConfigurations = ( 300 | 257B93211C2C426B0000FB6B /* Debug */, 301 | 257B93221C2C426B0000FB6B /* Release */, 302 | ); 303 | defaultConfigurationIsVisible = 0; 304 | defaultConfigurationName = Release; 305 | }; 306 | 257B93231C2C426B0000FB6B /* Build configuration list for PBXNativeTarget "ScrollingTabBarDemo" */ = { 307 | isa = XCConfigurationList; 308 | buildConfigurations = ( 309 | 257B93241C2C426B0000FB6B /* Debug */, 310 | 257B93251C2C426B0000FB6B /* Release */, 311 | ); 312 | defaultConfigurationIsVisible = 0; 313 | defaultConfigurationName = Release; 314 | }; 315 | /* End XCConfigurationList section */ 316 | }; 317 | rootObject = 257B92F31C2C426A0000FB6B /* Project object */; 318 | } 319 | -------------------------------------------------------------------------------- /ScrollingTabBarDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ScrollingTabBarDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AnimatedTabBar 4 | // 5 | // Created by Franklin Schrans on 24/12/2015. 6 | // Copyright © 2015 Franklin Schrans. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | UIApplication.shared.statusBarStyle = .lightContent 20 | return true 21 | } 22 | 23 | func applicationWillResignActive(_ application: UIApplication) { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | func applicationDidEnterBackground(_ application: UIApplication) { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | func applicationWillEnterForeground(_ application: UIApplication) { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | func applicationDidBecomeActive(_ application: UIApplication) { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | func applicationWillTerminate(_ application: UIApplication) { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /ScrollingTabBarDemo/Assets.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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /ScrollingTabBarDemo/Base.lproj/LaunchScreen.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 | 27 | 28 | -------------------------------------------------------------------------------- /ScrollingTabBarDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /ScrollingTabBarDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 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 | UIViewControllerBasedStatusBarAppearance 30 | 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ScrollingTabBarDemo/ScrollingTabBarUtils.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScrollingTabBarUtils.swift 3 | // ScrollingTabBarUtils 4 | // 5 | // Created by Franklin Schrans on 24/12/2015. 6 | // Copyright © 2015 Franklin Schrans. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ScrollingTabBarControllerDelegate: NSObject, UITabBarControllerDelegate { 12 | func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 13 | return ScrollingTransitionAnimator(tabBarController: tabBarController, lastIndex: tabBarController.selectedIndex) 14 | } 15 | } 16 | 17 | class ScrollingTransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning { 18 | weak var transitionContext: UIViewControllerContextTransitioning? 19 | var tabBarController: UITabBarController! 20 | var lastIndex = 0 21 | 22 | func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 23 | return 0.4 24 | } 25 | 26 | init(tabBarController: UITabBarController, lastIndex: Int) { 27 | self.tabBarController = tabBarController 28 | self.lastIndex = lastIndex 29 | } 30 | 31 | func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 32 | self.transitionContext = transitionContext 33 | 34 | let containerView = transitionContext.containerView 35 | let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) 36 | let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) 37 | 38 | containerView.addSubview(toViewController!.view) 39 | 40 | var viewWidth = toViewController!.view.bounds.width 41 | 42 | if tabBarController.selectedIndex < lastIndex { 43 | viewWidth = -viewWidth 44 | } 45 | 46 | toViewController!.view.transform = CGAffineTransform(translationX: viewWidth, y: 0) 47 | 48 | UIView.animate(withDuration: self.transitionDuration(using: (self.transitionContext)), delay: 0.0, usingSpringWithDamping: 1.2, initialSpringVelocity: 2.5, options: .overrideInheritedOptions, animations: { 49 | toViewController!.view.transform = CGAffineTransform.identity 50 | fromViewController!.view.transform = CGAffineTransform(translationX: -viewWidth, y: 0) 51 | }, completion: { _ in 52 | self.transitionContext?.completeTransition(!self.transitionContext!.transitionWasCancelled) 53 | fromViewController!.view.transform = CGAffineTransform.identity 54 | }) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/franklinsch/iOSScrollingTabBarAnimation/30220ebaeea942a2af41280027ca67d5e916df73/demo.gif --------------------------------------------------------------------------------