├── .swift-version ├── LICENSE ├── README.md ├── SwipeableViewController.podspec ├── SwipeableViewController.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── oscarapeland.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── SwipeableViewController ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── ExampleSwipeableViewController.swift ├── ExampleViewController.swift ├── Info.plist └── Source │ ├── SwipeableCell.swift │ ├── SwipeableCell.xib │ ├── SwipeableCollectionView.swift │ ├── SwipeableCollectionViewFlowLayout.swift │ ├── SwipeableItem.swift │ ├── SwipeableNavigationBar.swift │ ├── SwipeableNavigationController.swift │ └── SwipeableViewController.swift └── example.gif /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Oscar Apeland 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwipeableViewController 2 | 3 | [![Version](https://img.shields.io/cocoapods/v/SwipeableViewController.svg?style=flat)](http://cocoapods.org/pods/SwipeableViewController) 4 | [![License](https://img.shields.io/cocoapods/l/SwipeableViewController.svg?style=flat)](http://cocoapods.org/pods/SwipeableViewController) 5 | [![Platform](https://img.shields.io/cocoapods/p/SwipeableViewController.svg?style=flat)](http://cocoapods.org/pods/SwipeableViewController) 6 | 7 | ## Example 8 | 9 | To test the project, clone this repo and run SwipeableViewController.xcodeproj. 10 | ![Example gif](https://github.com/tiseoslo/SwipeableViewController/blob/master/example.gif) 11 | 12 | ## Requirements 13 | 14 | - iOS 9 15 | - Swift 4 16 | 17 | ## Installation 18 | 19 | SwipeableViewController is available through [CocoaPods](http://cocoapods.org). To install 20 | it, simply add the following line to your Podfile: 21 | 22 | ```ruby 23 | pod 'SwipeableViewController' 24 | ``` 25 | 26 | ## Usage 27 | ```swift 28 | // Make an instance of SwipeableNavigationController 29 | let navigationController = SwipeableNavigationController(navigationBarClass: SwipeableNavigationBar.self, toolbarClass: nil) 30 | 31 | // Make an instance of SwipeableViewController 32 | let viewController = SwipeableViewController() 33 | 34 | // Inject data 35 | viewController.swipeableItems = [SwipeableItem(title: "View 1", viewController: ExampleViewController()), 36 | SwipeableItem(title: "View 2", viewController: ExampleViewController()), 37 | SwipeableItem(title: "View 3", viewController: ExampleViewController())] 38 | viewController.selectedIndex = 1 39 | 40 | // Set the view to the navigation controller (if you want the SwipeableViewController at the root of your navigationController) 41 | navigationController.setViewControllers([viewController], animated: false) 42 | ``` 43 | 44 | And you're good to go! 45 | 46 | ## Author 47 | 48 | Oscar Apeland, oscar@tiseit.com 49 | 50 | ## License 51 | 52 | SwipeableViewController is available under the MIT license. See the LICENSE file for more info. 53 | -------------------------------------------------------------------------------- /SwipeableViewController.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'SwipeableViewController' 3 | s.version = '0.1.13' 4 | s.summary = 'A small UI component to build UIPageViewController-y views in your app.' 5 | 6 | s.description = <<-DESC 7 | A segmented header and a UIPageViewController all in one convenient package. 8 | DESC 9 | 10 | s.homepage = 'https://github.com/tise/SwipeableViewController' 11 | s.license = { :type => 'MIT', :file => 'LICENSE' } 12 | s.author = { 'Oscar Apeland' => 'oscar@tiseit.com' } 13 | s.source = { :git => 'https://github.com/tise/SwipeableViewController.git', :tag => s.version.to_s } 14 | 15 | s.ios.deployment_target = '9.0' 16 | s.source_files = 'SwipeableViewController/Source/*.{swift,xib}' 17 | 18 | end 19 | -------------------------------------------------------------------------------- /SwipeableViewController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 08A9E2F41F9E356C000B2729 /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2E41F9E356C000B2729 /* ExampleViewController.swift */; }; 11 | 08A9E2F51F9E356C000B2729 /* SwipeableNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2E61F9E356C000B2729 /* SwipeableNavigationBar.swift */; }; 12 | 08A9E2F61F9E356C000B2729 /* SwipeableItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2E71F9E356C000B2729 /* SwipeableItem.swift */; }; 13 | 08A9E2F71F9E356C000B2729 /* SwipeableCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2E81F9E356C000B2729 /* SwipeableCollectionView.swift */; }; 14 | 08A9E2F81F9E356C000B2729 /* SwipeableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2E91F9E356C000B2729 /* SwipeableCell.swift */; }; 15 | 08A9E2FA1F9E356C000B2729 /* SwipeableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2EB1F9E356C000B2729 /* SwipeableViewController.swift */; }; 16 | 08A9E2FB1F9E356C000B2729 /* SwipeableCollectionViewFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2EC1F9E356C000B2729 /* SwipeableCollectionViewFlowLayout.swift */; }; 17 | 08A9E2FC1F9E356C000B2729 /* SwipeableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 08A9E2ED1F9E356C000B2729 /* SwipeableCell.xib */; }; 18 | 08A9E2FD1F9E356C000B2729 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 08A9E2EE1F9E356C000B2729 /* Assets.xcassets */; }; 19 | 08A9E2FE1F9E356C000B2729 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 08A9E2EF1F9E356C000B2729 /* LaunchScreen.storyboard */; }; 20 | 08A9E2FF1F9E356C000B2729 /* ExampleSwipeableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2F11F9E356C000B2729 /* ExampleSwipeableViewController.swift */; }; 21 | 08A9E3001F9E356C000B2729 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E2F21F9E356C000B2729 /* AppDelegate.swift */; }; 22 | 08D0565D1FA723CD00300DBF /* SwipeableNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08D0565C1FA723CD00300DBF /* SwipeableNavigationController.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 08254DD41F8E9EDA006DD969 /* SwipingViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwipingViewController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 08A9E2E41F9E356C000B2729 /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = ""; }; 28 | 08A9E2E61F9E356C000B2729 /* SwipeableNavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeableNavigationBar.swift; sourceTree = ""; }; 29 | 08A9E2E71F9E356C000B2729 /* SwipeableItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeableItem.swift; sourceTree = ""; }; 30 | 08A9E2E81F9E356C000B2729 /* SwipeableCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeableCollectionView.swift; sourceTree = ""; }; 31 | 08A9E2E91F9E356C000B2729 /* SwipeableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeableCell.swift; sourceTree = ""; }; 32 | 08A9E2EB1F9E356C000B2729 /* SwipeableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeableViewController.swift; sourceTree = ""; }; 33 | 08A9E2EC1F9E356C000B2729 /* SwipeableCollectionViewFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeableCollectionViewFlowLayout.swift; sourceTree = ""; }; 34 | 08A9E2ED1F9E356C000B2729 /* SwipeableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SwipeableCell.xib; sourceTree = ""; }; 35 | 08A9E2EE1F9E356C000B2729 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 36 | 08A9E2F01F9E356C000B2729 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 37 | 08A9E2F11F9E356C000B2729 /* ExampleSwipeableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleSwipeableViewController.swift; sourceTree = ""; }; 38 | 08A9E2F21F9E356C000B2729 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | 08A9E2F31F9E356C000B2729 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 40 | 08D0565C1FA723CD00300DBF /* SwipeableNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeableNavigationController.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 08254DD11F8E9EDA006DD969 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 08254DCB1F8E9EDA006DD969 = { 55 | isa = PBXGroup; 56 | children = ( 57 | 08A9E2E31F9E356C000B2729 /* SwipeableViewController */, 58 | 08254DD51F8E9EDA006DD969 /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | 08254DD51F8E9EDA006DD969 /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 08254DD41F8E9EDA006DD969 /* SwipingViewController.app */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | 08A9E2E31F9E356C000B2729 /* SwipeableViewController */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 08A9E2E41F9E356C000B2729 /* ExampleViewController.swift */, 74 | 08A9E2E51F9E356C000B2729 /* Source */, 75 | 08A9E2EE1F9E356C000B2729 /* Assets.xcassets */, 76 | 08A9E2EF1F9E356C000B2729 /* LaunchScreen.storyboard */, 77 | 08A9E2F11F9E356C000B2729 /* ExampleSwipeableViewController.swift */, 78 | 08A9E2F21F9E356C000B2729 /* AppDelegate.swift */, 79 | 08A9E2F31F9E356C000B2729 /* Info.plist */, 80 | ); 81 | path = SwipeableViewController; 82 | sourceTree = ""; 83 | }; 84 | 08A9E2E51F9E356C000B2729 /* Source */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 08D0565C1FA723CD00300DBF /* SwipeableNavigationController.swift */, 88 | 08A9E2E61F9E356C000B2729 /* SwipeableNavigationBar.swift */, 89 | 08A9E2E71F9E356C000B2729 /* SwipeableItem.swift */, 90 | 08A9E2E81F9E356C000B2729 /* SwipeableCollectionView.swift */, 91 | 08A9E2E91F9E356C000B2729 /* SwipeableCell.swift */, 92 | 08A9E2EB1F9E356C000B2729 /* SwipeableViewController.swift */, 93 | 08A9E2EC1F9E356C000B2729 /* SwipeableCollectionViewFlowLayout.swift */, 94 | 08A9E2ED1F9E356C000B2729 /* SwipeableCell.xib */, 95 | ); 96 | path = Source; 97 | sourceTree = ""; 98 | }; 99 | /* End PBXGroup section */ 100 | 101 | /* Begin PBXNativeTarget section */ 102 | 08254DD31F8E9EDA006DD969 /* SwipingViewController */ = { 103 | isa = PBXNativeTarget; 104 | buildConfigurationList = 08254DE61F8E9EDA006DD969 /* Build configuration list for PBXNativeTarget "SwipingViewController" */; 105 | buildPhases = ( 106 | 08254DD01F8E9EDA006DD969 /* Sources */, 107 | 08254DD11F8E9EDA006DD969 /* Frameworks */, 108 | 08254DD21F8E9EDA006DD969 /* Resources */, 109 | ); 110 | buildRules = ( 111 | ); 112 | dependencies = ( 113 | ); 114 | name = SwipingViewController; 115 | productName = SwipingViewController; 116 | productReference = 08254DD41F8E9EDA006DD969 /* SwipingViewController.app */; 117 | productType = "com.apple.product-type.application"; 118 | }; 119 | /* End PBXNativeTarget section */ 120 | 121 | /* Begin PBXProject section */ 122 | 08254DCC1F8E9EDA006DD969 /* Project object */ = { 123 | isa = PBXProject; 124 | attributes = { 125 | LastSwiftUpdateCheck = 0900; 126 | LastUpgradeCheck = 0900; 127 | ORGANIZATIONNAME = Tise; 128 | TargetAttributes = { 129 | 08254DD31F8E9EDA006DD969 = { 130 | CreatedOnToolsVersion = 9.0; 131 | ProvisioningStyle = Automatic; 132 | }; 133 | }; 134 | }; 135 | buildConfigurationList = 08254DCF1F8E9EDA006DD969 /* Build configuration list for PBXProject "SwipeableViewController" */; 136 | compatibilityVersion = "Xcode 8.0"; 137 | developmentRegion = en; 138 | hasScannedForEncodings = 0; 139 | knownRegions = ( 140 | en, 141 | Base, 142 | ); 143 | mainGroup = 08254DCB1F8E9EDA006DD969; 144 | productRefGroup = 08254DD51F8E9EDA006DD969 /* Products */; 145 | projectDirPath = ""; 146 | projectRoot = ""; 147 | targets = ( 148 | 08254DD31F8E9EDA006DD969 /* SwipingViewController */, 149 | ); 150 | }; 151 | /* End PBXProject section */ 152 | 153 | /* Begin PBXResourcesBuildPhase section */ 154 | 08254DD21F8E9EDA006DD969 /* Resources */ = { 155 | isa = PBXResourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | 08A9E2FE1F9E356C000B2729 /* LaunchScreen.storyboard in Resources */, 159 | 08A9E2FD1F9E356C000B2729 /* Assets.xcassets in Resources */, 160 | 08A9E2FC1F9E356C000B2729 /* SwipeableCell.xib in Resources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXResourcesBuildPhase section */ 165 | 166 | /* Begin PBXSourcesBuildPhase section */ 167 | 08254DD01F8E9EDA006DD969 /* Sources */ = { 168 | isa = PBXSourcesBuildPhase; 169 | buildActionMask = 2147483647; 170 | files = ( 171 | 08D0565D1FA723CD00300DBF /* SwipeableNavigationController.swift in Sources */, 172 | 08A9E2F81F9E356C000B2729 /* SwipeableCell.swift in Sources */, 173 | 08A9E2FF1F9E356C000B2729 /* ExampleSwipeableViewController.swift in Sources */, 174 | 08A9E2F51F9E356C000B2729 /* SwipeableNavigationBar.swift in Sources */, 175 | 08A9E2FB1F9E356C000B2729 /* SwipeableCollectionViewFlowLayout.swift in Sources */, 176 | 08A9E2F61F9E356C000B2729 /* SwipeableItem.swift in Sources */, 177 | 08A9E2F41F9E356C000B2729 /* ExampleViewController.swift in Sources */, 178 | 08A9E2F71F9E356C000B2729 /* SwipeableCollectionView.swift in Sources */, 179 | 08A9E3001F9E356C000B2729 /* AppDelegate.swift in Sources */, 180 | 08A9E2FA1F9E356C000B2729 /* SwipeableViewController.swift in Sources */, 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXSourcesBuildPhase section */ 185 | 186 | /* Begin PBXVariantGroup section */ 187 | 08A9E2EF1F9E356C000B2729 /* LaunchScreen.storyboard */ = { 188 | isa = PBXVariantGroup; 189 | children = ( 190 | 08A9E2F01F9E356C000B2729 /* Base */, 191 | ); 192 | name = LaunchScreen.storyboard; 193 | sourceTree = ""; 194 | }; 195 | /* End PBXVariantGroup section */ 196 | 197 | /* Begin XCBuildConfiguration section */ 198 | 08254DE41F8E9EDA006DD969 /* Debug */ = { 199 | isa = XCBuildConfiguration; 200 | buildSettings = { 201 | ALWAYS_SEARCH_USER_PATHS = NO; 202 | CLANG_ANALYZER_NONNULL = YES; 203 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 204 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 205 | CLANG_CXX_LIBRARY = "libc++"; 206 | CLANG_ENABLE_MODULES = YES; 207 | CLANG_ENABLE_OBJC_ARC = YES; 208 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 209 | CLANG_WARN_BOOL_CONVERSION = YES; 210 | CLANG_WARN_COMMA = YES; 211 | CLANG_WARN_CONSTANT_CONVERSION = YES; 212 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 213 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 214 | CLANG_WARN_EMPTY_BODY = YES; 215 | CLANG_WARN_ENUM_CONVERSION = YES; 216 | CLANG_WARN_INFINITE_RECURSION = YES; 217 | CLANG_WARN_INT_CONVERSION = YES; 218 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 219 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 220 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 221 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 222 | CLANG_WARN_STRICT_PROTOTYPES = YES; 223 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 224 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 225 | CLANG_WARN_UNREACHABLE_CODE = YES; 226 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 227 | CODE_SIGN_IDENTITY = "iPhone Developer"; 228 | COPY_PHASE_STRIP = NO; 229 | DEBUG_INFORMATION_FORMAT = dwarf; 230 | ENABLE_STRICT_OBJC_MSGSEND = YES; 231 | ENABLE_TESTABILITY = YES; 232 | GCC_C_LANGUAGE_STANDARD = gnu11; 233 | GCC_DYNAMIC_NO_PIC = NO; 234 | GCC_NO_COMMON_BLOCKS = YES; 235 | GCC_OPTIMIZATION_LEVEL = 0; 236 | GCC_PREPROCESSOR_DEFINITIONS = ( 237 | "DEBUG=1", 238 | "$(inherited)", 239 | ); 240 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 241 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 242 | GCC_WARN_UNDECLARED_SELECTOR = YES; 243 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 244 | GCC_WARN_UNUSED_FUNCTION = YES; 245 | GCC_WARN_UNUSED_VARIABLE = YES; 246 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 247 | MTL_ENABLE_DEBUG_INFO = YES; 248 | ONLY_ACTIVE_ARCH = YES; 249 | SDKROOT = iphoneos; 250 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 251 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 252 | SWIFT_VERSION = 4.0; 253 | }; 254 | name = Debug; 255 | }; 256 | 08254DE51F8E9EDA006DD969 /* Release */ = { 257 | isa = XCBuildConfiguration; 258 | buildSettings = { 259 | ALWAYS_SEARCH_USER_PATHS = NO; 260 | CLANG_ANALYZER_NONNULL = YES; 261 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 262 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 263 | CLANG_CXX_LIBRARY = "libc++"; 264 | CLANG_ENABLE_MODULES = YES; 265 | CLANG_ENABLE_OBJC_ARC = YES; 266 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 267 | CLANG_WARN_BOOL_CONVERSION = YES; 268 | CLANG_WARN_COMMA = YES; 269 | CLANG_WARN_CONSTANT_CONVERSION = YES; 270 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 271 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 272 | CLANG_WARN_EMPTY_BODY = YES; 273 | CLANG_WARN_ENUM_CONVERSION = YES; 274 | CLANG_WARN_INFINITE_RECURSION = YES; 275 | CLANG_WARN_INT_CONVERSION = YES; 276 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 277 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 279 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 280 | CLANG_WARN_STRICT_PROTOTYPES = YES; 281 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 282 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | CODE_SIGN_IDENTITY = "iPhone Developer"; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 288 | ENABLE_NS_ASSERTIONS = NO; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | GCC_C_LANGUAGE_STANDARD = gnu11; 291 | GCC_NO_COMMON_BLOCKS = YES; 292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 294 | GCC_WARN_UNDECLARED_SELECTOR = YES; 295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 296 | GCC_WARN_UNUSED_FUNCTION = YES; 297 | GCC_WARN_UNUSED_VARIABLE = YES; 298 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 299 | MTL_ENABLE_DEBUG_INFO = NO; 300 | SDKROOT = iphoneos; 301 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 302 | SWIFT_VERSION = 4.0; 303 | VALIDATE_PRODUCT = YES; 304 | }; 305 | name = Release; 306 | }; 307 | 08254DE71F8E9EDA006DD969 /* Debug */ = { 308 | isa = XCBuildConfiguration; 309 | buildSettings = { 310 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 311 | CODE_SIGN_STYLE = Automatic; 312 | DEVELOPMENT_TEAM = 88F3596FP2; 313 | INFOPLIST_FILE = "$(SRCROOT)/SwipeableViewController/Info.plist"; 314 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 315 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 316 | PRODUCT_BUNDLE_IDENTIFIER = Tise.SwipingViewController; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_VERSION = 4.0; 319 | TARGETED_DEVICE_FAMILY = "1,2"; 320 | }; 321 | name = Debug; 322 | }; 323 | 08254DE81F8E9EDA006DD969 /* Release */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 327 | CODE_SIGN_STYLE = Automatic; 328 | DEVELOPMENT_TEAM = 88F3596FP2; 329 | INFOPLIST_FILE = "$(SRCROOT)/SwipeableViewController/Info.plist"; 330 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 331 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 332 | PRODUCT_BUNDLE_IDENTIFIER = Tise.SwipingViewController; 333 | PRODUCT_NAME = "$(TARGET_NAME)"; 334 | SWIFT_VERSION = 4.0; 335 | TARGETED_DEVICE_FAMILY = "1,2"; 336 | }; 337 | name = Release; 338 | }; 339 | /* End XCBuildConfiguration section */ 340 | 341 | /* Begin XCConfigurationList section */ 342 | 08254DCF1F8E9EDA006DD969 /* Build configuration list for PBXProject "SwipeableViewController" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | 08254DE41F8E9EDA006DD969 /* Debug */, 346 | 08254DE51F8E9EDA006DD969 /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | 08254DE61F8E9EDA006DD969 /* Build configuration list for PBXNativeTarget "SwipingViewController" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | 08254DE71F8E9EDA006DD969 /* Debug */, 355 | 08254DE81F8E9EDA006DD969 /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | /* End XCConfigurationList section */ 361 | }; 362 | rootObject = 08254DCC1F8E9EDA006DD969 /* Project object */; 363 | } 364 | -------------------------------------------------------------------------------- /SwipeableViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwipeableViewController.xcodeproj/xcuserdata/oscarapeland.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 12 | 13 | 14 | 16 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SwipeableViewController.xcodeproj/xcuserdata/oscarapeland.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SwipingViewController.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SwipeableViewController/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // AppDelegate.swift 4 | // SwipingViewController 5 | // 6 | // Created by Oscar Apeland on 11.10.2017. 7 | // Copyright © 2017 Tise. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 17 | window = UIWindow(frame: UIScreen.main.bounds) 18 | 19 | let navigationController = SwipeableNavigationController(navigationBarClass: SwipeableNavigationBar.self, toolbarClass: nil) 20 | let viewController = ExampleSwipeableViewController() 21 | viewController.swipeableItems = [SwipeableItem(title: "Recent", viewController: ExampleViewController()), 22 | SwipeableItem(title: "Explore", viewController: ExampleViewController()), 23 | SwipeableItem(title: "Browse", viewController: ExampleViewController())] 24 | viewController.selectedIndex = 1 25 | navigationController.setViewControllers([viewController], animated: false) 26 | 27 | window?.rootViewController = navigationController 28 | window?.makeKeyAndVisible() 29 | 30 | return true 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /SwipeableViewController/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /SwipeableViewController/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 | -------------------------------------------------------------------------------- /SwipeableViewController/ExampleSwipeableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleSwipeableViewController.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 13.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ExampleSwipeableViewController: SwipeableViewController { 12 | lazy var searchController = UISearchController(searchResultsController: { 13 | $0.view.backgroundColor = .red 14 | return $0 15 | }(UIViewController())) 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | if #available(iOS 11.0, *) { 20 | navigationItem.largeTitleDisplayMode = .always 21 | navigationItem.searchController = searchController 22 | } else { 23 | navigationItem.titleView = searchController.searchBar 24 | } 25 | 26 | definesPresentationContext = true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SwipeableViewController/ExampleViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleViewController.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 12.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ExampleViewController: UIViewController { 12 | lazy var collectionView: UICollectionView = { 13 | $0.backgroundColor = .white 14 | $0.alwaysBounceVertical = true 15 | $0.delegate = self 16 | $0.dataSource = self 17 | $0.autoresizingMask = [.flexibleHeight, .flexibleWidth] 18 | ($0.collectionViewLayout as? UICollectionViewFlowLayout)?.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0) 19 | 20 | return $0 21 | }(UICollectionView(frame: view.bounds, collectionViewLayout: UICollectionViewFlowLayout())) 22 | 23 | let cellColor = UIColor.random 24 | 25 | override func viewDidLoad() { 26 | super.viewDidLoad() 27 | view.addSubview(collectionView) 28 | if #available(iOS 11.0, *) { 29 | collectionView.contentInsetAdjustmentBehavior = .always 30 | } 31 | } 32 | } 33 | 34 | extension ExampleViewController: UICollectionViewDataSource, UICollectionViewDelegate { 35 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 36 | return 100 37 | } 38 | 39 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 40 | collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell") 41 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) 42 | cell.backgroundColor = cellColor 43 | 44 | return cell 45 | } 46 | 47 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 48 | let vc = UICollectionViewController(collectionViewLayout: UICollectionViewFlowLayout()) 49 | 50 | vc.collectionView?.backgroundColor = .white 51 | vc.collectionView?.dataSource = self 52 | vc.collectionView?.delegate = self 53 | 54 | navigationController?.pushViewController(vc, animated: true) 55 | } 56 | } 57 | 58 | extension UIColor { 59 | class var random: UIColor { 60 | func random() -> CGFloat { 61 | return CGFloat(arc4random()) / CGFloat(UInt32.max) 62 | } 63 | 64 | return UIColor(red: random(), green: random(), blue: random(), alpha: 1.0) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SwipeableViewController/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiperCell.swift 3 | // SwiperNavigationBar 4 | // 5 | // Created by Oscar Apeland on 11.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class SwipeableCell: UICollectionViewCell { 12 | static let id = "SwipeableCell" 13 | 14 | @IBOutlet weak var label: UILabel! 15 | } 16 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableCollectionView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableCollectionView.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 12.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | typealias CollectionViewController = UICollectionViewDelegate & UICollectionViewDataSource 12 | 13 | open class SwipeableCollectionView: UICollectionView { 14 | var controller: CollectionViewController? { 15 | didSet { 16 | delegate = controller 17 | dataSource = controller 18 | 19 | if controller !== oldValue { 20 | reloadData() 21 | } 22 | } 23 | } 24 | 25 | override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { 26 | super.init(frame: frame, collectionViewLayout: layout) 27 | setup() 28 | } 29 | 30 | required public init?(coder aDecoder: NSCoder) { 31 | super.init(coder: aDecoder) 32 | setup() 33 | } 34 | 35 | private func setup() { 36 | backgroundColor = .clear 37 | register(UINib(nibName: SwipeableCell.id, bundle: Bundle(for: classForCoder)), forCellWithReuseIdentifier: SwipeableCell.id) 38 | alwaysBounceHorizontal = true 39 | showsHorizontalScrollIndicator = false 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableCollectionViewFlowLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableCollectionViewFlowLayout.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 12.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class SwipeableCollectionViewFlowLayout: UICollectionViewFlowLayout { 12 | override init() { 13 | super.init() 14 | setup() 15 | } 16 | 17 | required public init?(coder aDecoder: NSCoder) { 18 | super.init(coder: aDecoder) 19 | setup() 20 | } 21 | 22 | private var collectionViewObservation: NSKeyValueObservation? 23 | private func setup() { 24 | collectionViewObservation = observe(\.collectionView, options: [.new]) { (layout, change) in 25 | guard let newCollectionView = change.newValue as? UICollectionView, let layout = newCollectionView.collectionViewLayout as? SwipeableCollectionViewFlowLayout else { 26 | return 27 | } 28 | 29 | // 30 | layout.sectionInset = UIEdgeInsets(top: 0.0, left: 10.0, bottom: 0.0, right: 10.0) 31 | layout.estimatedItemSize = CGSize(width: 60, height: newCollectionView.frame.height) 32 | layout.minimumInteritemSpacing = .leastNonzeroMagnitude 33 | layout.minimumLineSpacing = .leastNonzeroMagnitude 34 | layout.scrollDirection = .horizontal 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableItem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableItem.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 11.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | public struct SwipeableItem { 13 | public var title: String 14 | public var viewController: UIViewController 15 | 16 | public init(title: String, viewController: UIViewController) { 17 | self.title = title 18 | self.viewController = viewController 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableNavigationBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableNavigationBar.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 12.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class SwipeableNavigationBar: UINavigationBar { 12 | public override init(frame: CGRect) { 13 | super.init(frame: frame) 14 | setup() 15 | } 16 | 17 | public required init?(coder aDecoder: NSCoder) { 18 | super.init(coder: aDecoder) 19 | setup() 20 | } 21 | 22 | private func setup() { 23 | if #available(iOS 11.0, *) { 24 | largeTitleTextAttributes = [.foregroundColor: UIColor.clear] 25 | prefersLargeTitles = true 26 | } 27 | } 28 | 29 | // MARK: Properties 30 | lazy var largeTitleView: UIView? = { 31 | return subviews.first { 32 | String(describing: type(of: $0)) == "_UINavigationBarLargeTitleView" 33 | } 34 | }() 35 | 36 | var largeTitleLabel: UILabel? { 37 | return largeTitleView?.subviews.first { $0 is UILabel } as? UILabel 38 | } 39 | 40 | lazy var collectionView: SwipeableCollectionView = { 41 | $0.autoresizingMask = [.flexibleWidth, .flexibleTopMargin] 42 | 43 | return $0 44 | }(SwipeableCollectionView(frame: largeTitleView!.bounds, 45 | collectionViewLayout: SwipeableCollectionViewFlowLayout())) 46 | } 47 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableNavigationController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableNavigationController.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 30.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | open class SwipeableNavigationController: UINavigationController { 13 | override open func viewDidLoad() { 14 | super.viewDidLoad() 15 | delegate = self 16 | } 17 | } 18 | 19 | extension SwipeableNavigationController: UINavigationControllerDelegate { 20 | open func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { 21 | updateFor(viewController: viewController) 22 | } 23 | 24 | open func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) { 25 | updateFor(viewController: viewController) 26 | 27 | if let collectionView = (navigationBar as? SwipeableNavigationBar)?.collectionView, let superview = collectionView.superview { 28 | superview.bringSubview(toFront: collectionView) 29 | } 30 | } 31 | 32 | private func updateFor(viewController: UIViewController) { 33 | let isSwipeable = viewController is SwipeableViewController 34 | 35 | if #available(iOS 11, *) { 36 | viewController.navigationItem.largeTitleDisplayMode = isSwipeable ? .always : .never 37 | } 38 | 39 | if #available(iOS 11, *), let collectionView = (navigationBar as? SwipeableNavigationBar)?.collectionView { 40 | collectionView.isHidden = !isSwipeable 41 | } else if let collectionView = (viewController as? SwipeableViewController)?.collectionView { 42 | collectionView.isHidden = !isSwipeable 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SwipeableViewController/Source/SwipeableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SwipingViewController 4 | // 5 | // Created by Oscar Apeland on 11.10.2017. 6 | // Copyright © 2017 Tise. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum PanDirection { 12 | case rightToLeft, leftToRight 13 | 14 | static func directionFor(velocity: CGPoint) -> PanDirection { 15 | return velocity.x < 0 ? .rightToLeft : leftToRight 16 | } 17 | } 18 | 19 | open class SwipeableViewController: UIViewController { 20 | // MARK: Swipeable properties 21 | open var swipeableItems: [SwipeableItem] = [] 22 | open var selectedIndex: Int! 23 | 24 | // MARK: UI properties 25 | private lazy var panGestureRecognizer: UIPanGestureRecognizer = { 26 | $0.delegate = self 27 | return $0 28 | }(UIPanGestureRecognizer(target: self, action: #selector(viewPanned(_:)))) 29 | 30 | private var navigationBar: SwipeableNavigationBar! { 31 | return navigationController!.navigationBar as! SwipeableNavigationBar 32 | } 33 | 34 | var collectionView: SwipeableCollectionView? { 35 | if #available(iOS 11, *) { 36 | return navigationBar.collectionView 37 | } else { 38 | return swipeableCollectionView 39 | } 40 | } 41 | 42 | lazy var swipeableCollectionView: SwipeableCollectionView = { 43 | return SwipeableCollectionView(frame: CGRect(x: 0, y: 64.0, width: self.view.bounds.width, height: 52.0), 44 | collectionViewLayout: SwipeableCollectionViewFlowLayout()) 45 | }() 46 | 47 | // MARK: Life cycle 48 | override open func viewDidLoad() { 49 | super.viewDidLoad() 50 | 51 | // Safeguards 52 | guard !swipeableItems.isEmpty else { 53 | fatalError("swipableItems is empty.") 54 | } 55 | 56 | guard 0...swipeableItems.count ~= selectedIndex else { 57 | fatalError("startIndex out of range.") 58 | } 59 | 60 | // Setup - Custom transitions 61 | let initialItem = swipeableItems[selectedIndex] 62 | view.addGestureRecognizer(panGestureRecognizer) 63 | 64 | // Setup - Navigation bar 65 | navigationItem.title = initialItem.title 66 | 67 | if #available(iOS 11.0, *) { 68 | navigationItem.largeTitleDisplayMode = .always 69 | } 70 | 71 | // Setup - View 72 | view.backgroundColor = .white 73 | 74 | 75 | // On iOS <11 we add the collectionView underneath the navigation bar instead of inside. 76 | // Negative OS check currently impossible 77 | if #available(iOS 11, *) {} 78 | else { 79 | swipeableCollectionView.translatesAutoresizingMaskIntoConstraints = false 80 | automaticallyAdjustsScrollViewInsets = false 81 | 82 | view.addSubview(swipeableCollectionView) 83 | 84 | NSLayoutConstraint.activate([collectionView!.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor, constant: 64.0), 85 | collectionView!.heightAnchor.constraint(equalToConstant: 52.1), 86 | collectionView!.trailingAnchor.constraint(equalTo: view.trailingAnchor), 87 | collectionView!.leadingAnchor.constraint(equalTo: view.leadingAnchor)]) 88 | } 89 | 90 | add(childViewController: initialItem.viewController) 91 | } 92 | 93 | override open func viewDidAppear(_ animated: Bool) { 94 | super.viewDidAppear(animated) 95 | if #available(iOS 11, *) { 96 | if let titleView = navigationBar.largeTitleView, titleView.subviews.filter ({ $0 is UICollectionView }).isEmpty { 97 | navigationBar.largeTitleView!.addSubview(navigationBar.collectionView) 98 | } 99 | } 100 | 101 | collectionView?.controller = self 102 | } 103 | 104 | // MARK: Convenience 105 | /// Convenience methods for swapping out two child view controllers without animation. 106 | private func switchChildViewController(from fromVc: UIViewController, to toVc: UIViewController) { 107 | remove(childViewController: fromVc) 108 | add(childViewController: toVc) 109 | } 110 | 111 | private func remove(childViewController: UIViewController) { 112 | childViewController.willMove(toParentViewController: nil) 113 | childViewController.view.removeFromSuperview() 114 | childViewController.removeFromParentViewController() 115 | } 116 | 117 | /** 118 | Do all the required UIKit calls for adding a child view controller. 119 | - parameter childViewController: The controller to add. 120 | - returns: The view of the added view controller. 121 | */ 122 | @discardableResult 123 | private func add(childViewController: UIViewController) -> UIView { 124 | childViewController.willMove(toParentViewController: self) 125 | addChildViewController(childViewController) 126 | view.addSubview(childViewController.view) 127 | childViewController.didMove(toParentViewController: self) 128 | 129 | if #available(iOS 11, *) {} 130 | else { 131 | childViewController.view.translatesAutoresizingMaskIntoConstraints = false 132 | childViewController.view.setContentCompressionResistancePriority(.defaultLow, for: .vertical) 133 | 134 | NSLayoutConstraint.activate([childViewController.view.topAnchor.constraint(equalTo: collectionView!.bottomAnchor), 135 | childViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), 136 | childViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), 137 | childViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor)]) 138 | } 139 | 140 | return childViewController.view 141 | } 142 | 143 | /// The view controller after the current child view controller, if there is any. 144 | func nextViewController() -> UIViewController? { 145 | let nextIndex = selectedIndex + 1 146 | return swipeableItems.indices.contains(nextIndex) ? swipeableItems[nextIndex].viewController : nil 147 | } 148 | 149 | /// The view controller before the current child view controller, if there is any. 150 | func previousViewController() -> UIViewController? { 151 | let previousIndex = selectedIndex - 1 152 | return swipeableItems.indices.contains(previousIndex) ? swipeableItems[previousIndex].viewController : nil 153 | } 154 | 155 | // MARK: Animation 156 | private var startPoint: CGPoint? 157 | private var startDirection: PanDirection? 158 | private var animationProgress: CGFloat = 0.0 159 | private weak var animatingViewController: UIViewController? 160 | private var didForceCancel = false 161 | 162 | @objc 163 | func viewPanned(_ gesture: UIPanGestureRecognizer) { 164 | let velocity = gesture.velocity(in: gesture.view) 165 | let direction = PanDirection.directionFor(velocity: velocity) 166 | 167 | // Animate 168 | switch gesture.state { 169 | case .began: 170 | // If there's nothing to show, cancel the gesture 171 | guard let viewController = (direction == .rightToLeft) ? nextViewController() : previousViewController() else { 172 | didForceCancel = true 173 | gesture.isEnabled = false; gesture.isEnabled = true 174 | return 175 | } 176 | 177 | // Add the view offscreen 178 | add(childViewController: viewController) 179 | 180 | // Keep for animation 181 | startPoint = gesture.location(in: view!) 182 | startDirection = direction 183 | animatingViewController = viewController 184 | 185 | // Render the layer offscreen 186 | switch startDirection! { 187 | case .leftToRight: viewController.view.transform = CGAffineTransform(translationX: -view.bounds.width, y: 0) 188 | case .rightToLeft: viewController.view.transform = CGAffineTransform(translationX: view.bounds.width, y: 0) 189 | } 190 | 191 | case .changed: 192 | let location = gesture.location(in: view!) 193 | let relativeLocation = location.x - startPoint!.x 194 | 195 | // If we have swiped beyond the initial touch point, cancel the animation. 196 | // Switching isEnabled calls .cancelled which resets the transition before it calls .began which will restart it in the other direction 197 | if (location.x > startPoint!.x && startDirection! == .rightToLeft) || (location.x < startPoint!.x && startDirection! == .leftToRight) { 198 | self.endAnimation() 199 | gesture.isEnabled = false; gesture.isEnabled = true 200 | return 201 | } 202 | 203 | switch startDirection! { 204 | case .leftToRight: 205 | animatingViewController!.view.transform = CGAffineTransform(translationX: relativeLocation - view.frame.width, y: 0) 206 | swipeableItems[selectedIndex].viewController.view.transform = CGAffineTransform(translationX: relativeLocation, y: 0) 207 | 208 | case .rightToLeft: 209 | animatingViewController!.view.transform = CGAffineTransform(translationX: relativeLocation + view.frame.width, y: 0) 210 | swipeableItems[selectedIndex].viewController.view.transform = CGAffineTransform(translationX: relativeLocation, y: 0) 211 | } 212 | 213 | case .ended, .cancelled: 214 | // If we cancel the gesture in .began, return because all ivars are nil and there's nothing to cancel. 215 | guard !didForceCancel else { 216 | didForceCancel = false 217 | return 218 | } 219 | 220 | guard let startPoint = startPoint, let startDirection = startDirection, let animatingViewController = animatingViewController else { 221 | return 222 | } 223 | 224 | let location = gesture.location(in: view!) 225 | let relativeLocation = location.x - startPoint.x 226 | 227 | let completionTreshold: CGFloat = 0.7 228 | let velocityTreshold: CGFloat = 1000.0 229 | 230 | var isDone = false 231 | var swipeDistance: CGFloat = 0.0 232 | 233 | // Decide if we are done 234 | switch startDirection { 235 | case .leftToRight: 236 | swipeDistance = view.frame.width - startPoint.x 237 | let progress = relativeLocation / swipeDistance // 0...1, not 1...100 238 | 239 | isDone = progress > completionTreshold || velocity.x > velocityTreshold 240 | 241 | case .rightToLeft: 242 | swipeDistance = startPoint.x 243 | let progress = relativeLocation / swipeDistance 244 | 245 | isDone = fabs(progress) > completionTreshold || velocity.x < -velocityTreshold 246 | } 247 | 248 | 249 | // Complete animation and clean up 250 | if isDone { 251 | // Complete the animation 252 | UIView.animate(withDuration: 0.25, delay: 0.0, 253 | options: [.curveEaseOut, .beginFromCurrentState, .allowAnimatedContent], 254 | animations: { 255 | animatingViewController.view.transform = .identity 256 | let previousView = self.swipeableItems[self.selectedIndex].viewController.view! 257 | let translationX = (self.startDirection == .leftToRight) ? previousView.frame.width : -previousView.frame.width 258 | previousView.transform = CGAffineTransform(translationX: translationX, y: 0) 259 | }, completion: { (isFinished) in 260 | 261 | self.remove(childViewController: self.swipeableItems[self.selectedIndex].viewController) 262 | self.endAnimation() 263 | 264 | let nextIndex = self.selectedIndex + (direction == .leftToRight ? -1 : +1) 265 | let previousIndexPath = IndexPath(item: self.selectedIndex, section: 0) 266 | let nextIndexPath = IndexPath(item: nextIndex, section: 0) 267 | 268 | (self.collectionView?.cellForItem(at: previousIndexPath) as? SwipeableCell)?.label.textColor = #colorLiteral(red: 0.1490196078, green: 0.1490196078, blue: 0.1490196078, alpha: 0.5) 269 | (self.collectionView?.cellForItem(at: nextIndexPath) as? SwipeableCell)?.label.textColor = #colorLiteral(red: 0.9098039216, green: 0.4156862745, blue: 0.3764705882, alpha: 1) 270 | 271 | self.selectedIndex = nextIndex 272 | self.navigationItem.title = self.swipeableItems[self.selectedIndex].title 273 | self.collectionView!.selectItem(at: IndexPath(item: self.selectedIndex, section: 0), animated: true, scrollPosition: .centeredHorizontally) 274 | }) 275 | } else { 276 | //Cancel the animation 277 | UIView.animate(withDuration: 0.25, delay: 0.0, 278 | options: [.curveEaseOut, .beginFromCurrentState, .allowAnimatedContent], 279 | animations: { 280 | self.swipeableItems[self.selectedIndex].viewController.view!.transform = .identity 281 | let previousView = self.animatingViewController!.view! 282 | let translationX = (self.startDirection! == .leftToRight) ? -previousView.frame.width : previousView.frame.width 283 | previousView.transform = CGAffineTransform(translationX: translationX, y: 0) 284 | }, completion: { (isFinished) in 285 | self.remove(childViewController: self.animatingViewController!) 286 | self.endAnimation() 287 | }) 288 | } 289 | 290 | default: 291 | break 292 | } 293 | } 294 | 295 | private func endAnimation() { 296 | startPoint = nil 297 | startDirection = nil 298 | animationProgress = 0 299 | } 300 | 301 | open func swipeTo(index nextIndex: Int) { 302 | guard swipeableItems.indices.contains(nextIndex) else { 303 | return 304 | } 305 | 306 | let direction: PanDirection = nextIndex > selectedIndex ? .leftToRight : .rightToLeft 307 | 308 | let lowerBound = min(selectedIndex, nextIndex) 309 | let upperBound = max(selectedIndex, nextIndex) 310 | var viewControllers = swipeableItems[lowerBound...upperBound].map { $0.viewController } 311 | 312 | if direction == .rightToLeft { 313 | viewControllers.reverse() 314 | } 315 | 316 | for (index, viewController) in viewControllers.enumerated() { 317 | self.add(childViewController: viewController) 318 | let offsetX: CGFloat = (direction == .leftToRight) ? viewController.view.frame.width : -viewController.view.frame.width 319 | viewController.view.transform = CGAffineTransform(translationX: CGFloat(index) * offsetX, y: 0) 320 | } 321 | 322 | UIView.animate(withDuration: 0.25, delay: 0.0, 323 | options: [.curveEaseOut, .beginFromCurrentState, .allowAnimatedContent], 324 | animations: { 325 | for (reversedIndex, viewController) in viewControllers.reversed().enumerated() { 326 | let offsetX: CGFloat = (direction == .leftToRight) ? -viewController.view.frame.width : viewController.view.frame.width 327 | viewController.view.transform = CGAffineTransform(translationX: CGFloat(reversedIndex) * offsetX, y: 0) 328 | } 329 | }) { (isFinished) in 330 | viewControllers.dropLast().forEach(self.remove) 331 | 332 | let previousIndexPath = IndexPath(item: self.selectedIndex, section: 0) 333 | let nextIndexPath = IndexPath(item: nextIndex, section: 0) 334 | 335 | (self.collectionView?.cellForItem(at: previousIndexPath) as? SwipeableCell)?.label.textColor = #colorLiteral(red: 0.1490196078, green: 0.1490196078, blue: 0.1490196078, alpha: 0.5) 336 | (self.collectionView?.cellForItem(at: nextIndexPath) as? SwipeableCell)?.label.textColor = #colorLiteral(red: 0.9098039216, green: 0.4156862745, blue: 0.3764705882, alpha: 1) 337 | 338 | self.selectedIndex = nextIndex 339 | self.navigationItem.title = self.swipeableItems[self.selectedIndex].title 340 | self.collectionView!.selectItem(at: IndexPath(item: self.selectedIndex, section: 0), animated: true, scrollPosition: .centeredHorizontally) 341 | } 342 | } 343 | } 344 | 345 | extension SwipeableViewController: UICollectionViewDataSource, UICollectionViewDelegate { 346 | open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 347 | return swipeableItems.count 348 | } 349 | 350 | open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 351 | guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SwipeableCell.id, for: indexPath) as? SwipeableCell else { 352 | fatalError() 353 | } 354 | 355 | cell.label.text = swipeableItems[indexPath.row].title 356 | cell.label.textColor = indexPath.row == selectedIndex ? #colorLiteral(red: 0.9098039216, green: 0.4156862745, blue: 0.3764705882, alpha: 1) : #colorLiteral(red: 0.1490196078, green: 0.1490196078, blue: 0.1490196078, alpha: 0.5) 357 | 358 | return cell 359 | } 360 | 361 | open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 362 | swipeTo(index: indexPath.row) 363 | } 364 | } 365 | 366 | extension SwipeableViewController: UIGestureRecognizerDelegate { 367 | open func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { 368 | if let pan = gestureRecognizer as? UIPanGestureRecognizer { 369 | let velocity = pan.velocity(in: view) 370 | return fabs(velocity.x) > fabs(velocity.y) 371 | } 372 | return true 373 | } 374 | } 375 | -------------------------------------------------------------------------------- /example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tise/SwipeableViewController/c4847f93de2d70e73cbcb69e1b36be0f8bbf6af0/example.gif --------------------------------------------------------------------------------