├── .gitignore ├── DraggableViewController.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── DraggableViewController ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── BaseAnimator.swift ├── BottomBar.swift ├── Info.plist ├── MiniToLargeViewAnimator.swift ├── MiniToLargeViewInteractive.swift ├── NextViewController.swift └── ViewController.swift ├── README.md └── draggableViewController.gif /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Xcode 4 | # 5 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 6 | 7 | ## Build generated 8 | build/ 9 | DerivedData 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | 22 | ## Other 23 | *.xccheckout 24 | *.moved-aside 25 | *.xcuserstate 26 | *.xcscmblueprint 27 | 28 | ## Obj-C/Swift specific 29 | *.hmap 30 | *.ipa 31 | 32 | ## Playgrounds 33 | timeline.xctimeline 34 | playground.xcworkspace 35 | 36 | # Swift Package Manager 37 | # 38 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 39 | # Packages/ 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 63 | 64 | fastlane/report.xml 65 | fastlane/screenshots 66 | -------------------------------------------------------------------------------- /DraggableViewController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4B5F2C881CECAF590001CEFE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5F2C871CECAF590001CEFE /* AppDelegate.swift */; }; 11 | 4B5F2C8A1CECAF590001CEFE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5F2C891CECAF590001CEFE /* ViewController.swift */; }; 12 | 4B5F2C8D1CECAF5A0001CEFE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B5F2C8B1CECAF5A0001CEFE /* Main.storyboard */; }; 13 | 4B5F2C8F1CECAF5A0001CEFE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B5F2C8E1CECAF5A0001CEFE /* Assets.xcassets */; }; 14 | 4B5F2C921CECAF5A0001CEFE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B5F2C901CECAF5A0001CEFE /* LaunchScreen.storyboard */; }; 15 | 4B5F2C9A1CECB0B40001CEFE /* NextViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5F2C991CECB0B40001CEFE /* NextViewController.swift */; }; 16 | 4B5F2C9C1CECB0EF0001CEFE /* BaseAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5F2C9B1CECB0EF0001CEFE /* BaseAnimator.swift */; }; 17 | 4B5F2C9F1CECB65F0001CEFE /* MiniToLargeViewAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5F2C9E1CECB65F0001CEFE /* MiniToLargeViewAnimator.swift */; }; 18 | 4B5F2CA11CECB8350001CEFE /* MiniToLargeViewInteractive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5F2CA01CECB8350001CEFE /* MiniToLargeViewInteractive.swift */; }; 19 | 4B5F2CA31CECBB9A0001CEFE /* BottomBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B5F2CA21CECBB9A0001CEFE /* BottomBar.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 4B5F2C841CECAF590001CEFE /* DraggableViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DraggableViewController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 4B5F2C871CECAF590001CEFE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 25 | 4B5F2C891CECAF590001CEFE /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 26 | 4B5F2C8C1CECAF5A0001CEFE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | 4B5F2C8E1CECAF5A0001CEFE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 4B5F2C911CECAF5A0001CEFE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 4B5F2C931CECAF5A0001CEFE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 4B5F2C991CECB0B40001CEFE /* NextViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NextViewController.swift; sourceTree = ""; }; 31 | 4B5F2C9B1CECB0EF0001CEFE /* BaseAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseAnimator.swift; sourceTree = ""; }; 32 | 4B5F2C9E1CECB65F0001CEFE /* MiniToLargeViewAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MiniToLargeViewAnimator.swift; sourceTree = ""; }; 33 | 4B5F2CA01CECB8350001CEFE /* MiniToLargeViewInteractive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MiniToLargeViewInteractive.swift; sourceTree = ""; }; 34 | 4B5F2CA21CECBB9A0001CEFE /* BottomBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomBar.swift; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 4B5F2C811CECAF590001CEFE /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 4B5F2C7B1CECAF590001CEFE = { 49 | isa = PBXGroup; 50 | children = ( 51 | 4B5F2C861CECAF590001CEFE /* DraggableViewController */, 52 | 4B5F2C851CECAF590001CEFE /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 4B5F2C851CECAF590001CEFE /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 4B5F2C841CECAF590001CEFE /* DraggableViewController.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 4B5F2C861CECAF590001CEFE /* DraggableViewController */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 4B5F2C871CECAF590001CEFE /* AppDelegate.swift */, 68 | 4B5F2C891CECAF590001CEFE /* ViewController.swift */, 69 | 4B5F2C991CECB0B40001CEFE /* NextViewController.swift */, 70 | 4B5F2CA21CECBB9A0001CEFE /* BottomBar.swift */, 71 | 4B5F2C9D1CECB3E00001CEFE /* Transition Animators */, 72 | 4B5F2C8B1CECAF5A0001CEFE /* Main.storyboard */, 73 | 4B5F2C8E1CECAF5A0001CEFE /* Assets.xcassets */, 74 | 4B5F2C901CECAF5A0001CEFE /* LaunchScreen.storyboard */, 75 | 4B5F2C931CECAF5A0001CEFE /* Info.plist */, 76 | ); 77 | path = DraggableViewController; 78 | sourceTree = ""; 79 | }; 80 | 4B5F2C9D1CECB3E00001CEFE /* Transition Animators */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 4B5F2C9B1CECB0EF0001CEFE /* BaseAnimator.swift */, 84 | 4B5F2C9E1CECB65F0001CEFE /* MiniToLargeViewAnimator.swift */, 85 | 4B5F2CA01CECB8350001CEFE /* MiniToLargeViewInteractive.swift */, 86 | ); 87 | name = "Transition Animators"; 88 | sourceTree = ""; 89 | }; 90 | /* End PBXGroup section */ 91 | 92 | /* Begin PBXNativeTarget section */ 93 | 4B5F2C831CECAF590001CEFE /* DraggableViewController */ = { 94 | isa = PBXNativeTarget; 95 | buildConfigurationList = 4B5F2C961CECAF5A0001CEFE /* Build configuration list for PBXNativeTarget "DraggableViewController" */; 96 | buildPhases = ( 97 | 4B5F2C801CECAF590001CEFE /* Sources */, 98 | 4B5F2C811CECAF590001CEFE /* Frameworks */, 99 | 4B5F2C821CECAF590001CEFE /* Resources */, 100 | ); 101 | buildRules = ( 102 | ); 103 | dependencies = ( 104 | ); 105 | name = DraggableViewController; 106 | productName = DraggableViewController; 107 | productReference = 4B5F2C841CECAF590001CEFE /* DraggableViewController.app */; 108 | productType = "com.apple.product-type.application"; 109 | }; 110 | /* End PBXNativeTarget section */ 111 | 112 | /* Begin PBXProject section */ 113 | 4B5F2C7C1CECAF590001CEFE /* Project object */ = { 114 | isa = PBXProject; 115 | attributes = { 116 | LastSwiftUpdateCheck = 0730; 117 | LastUpgradeCheck = 0730; 118 | ORGANIZATIONNAME = "Jiri Ostatnicky"; 119 | TargetAttributes = { 120 | 4B5F2C831CECAF590001CEFE = { 121 | CreatedOnToolsVersion = 7.3.1; 122 | }; 123 | }; 124 | }; 125 | buildConfigurationList = 4B5F2C7F1CECAF590001CEFE /* Build configuration list for PBXProject "DraggableViewController" */; 126 | compatibilityVersion = "Xcode 3.2"; 127 | developmentRegion = English; 128 | hasScannedForEncodings = 0; 129 | knownRegions = ( 130 | en, 131 | Base, 132 | ); 133 | mainGroup = 4B5F2C7B1CECAF590001CEFE; 134 | productRefGroup = 4B5F2C851CECAF590001CEFE /* Products */; 135 | projectDirPath = ""; 136 | projectRoot = ""; 137 | targets = ( 138 | 4B5F2C831CECAF590001CEFE /* DraggableViewController */, 139 | ); 140 | }; 141 | /* End PBXProject section */ 142 | 143 | /* Begin PBXResourcesBuildPhase section */ 144 | 4B5F2C821CECAF590001CEFE /* Resources */ = { 145 | isa = PBXResourcesBuildPhase; 146 | buildActionMask = 2147483647; 147 | files = ( 148 | 4B5F2C921CECAF5A0001CEFE /* LaunchScreen.storyboard in Resources */, 149 | 4B5F2C8F1CECAF5A0001CEFE /* Assets.xcassets in Resources */, 150 | 4B5F2C8D1CECAF5A0001CEFE /* Main.storyboard in Resources */, 151 | ); 152 | runOnlyForDeploymentPostprocessing = 0; 153 | }; 154 | /* End PBXResourcesBuildPhase section */ 155 | 156 | /* Begin PBXSourcesBuildPhase section */ 157 | 4B5F2C801CECAF590001CEFE /* Sources */ = { 158 | isa = PBXSourcesBuildPhase; 159 | buildActionMask = 2147483647; 160 | files = ( 161 | 4B5F2CA11CECB8350001CEFE /* MiniToLargeViewInteractive.swift in Sources */, 162 | 4B5F2C8A1CECAF590001CEFE /* ViewController.swift in Sources */, 163 | 4B5F2CA31CECBB9A0001CEFE /* BottomBar.swift in Sources */, 164 | 4B5F2C9A1CECB0B40001CEFE /* NextViewController.swift in Sources */, 165 | 4B5F2C9F1CECB65F0001CEFE /* MiniToLargeViewAnimator.swift in Sources */, 166 | 4B5F2C881CECAF590001CEFE /* AppDelegate.swift in Sources */, 167 | 4B5F2C9C1CECB0EF0001CEFE /* BaseAnimator.swift in Sources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXSourcesBuildPhase section */ 172 | 173 | /* Begin PBXVariantGroup section */ 174 | 4B5F2C8B1CECAF5A0001CEFE /* Main.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | 4B5F2C8C1CECAF5A0001CEFE /* Base */, 178 | ); 179 | name = Main.storyboard; 180 | sourceTree = ""; 181 | }; 182 | 4B5F2C901CECAF5A0001CEFE /* LaunchScreen.storyboard */ = { 183 | isa = PBXVariantGroup; 184 | children = ( 185 | 4B5F2C911CECAF5A0001CEFE /* Base */, 186 | ); 187 | name = LaunchScreen.storyboard; 188 | sourceTree = ""; 189 | }; 190 | /* End PBXVariantGroup section */ 191 | 192 | /* Begin XCBuildConfiguration section */ 193 | 4B5F2C941CECAF5A0001CEFE /* Debug */ = { 194 | isa = XCBuildConfiguration; 195 | buildSettings = { 196 | ALWAYS_SEARCH_USER_PATHS = NO; 197 | CLANG_ANALYZER_NONNULL = YES; 198 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 199 | CLANG_CXX_LIBRARY = "libc++"; 200 | CLANG_ENABLE_MODULES = YES; 201 | CLANG_ENABLE_OBJC_ARC = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 205 | CLANG_WARN_EMPTY_BODY = YES; 206 | CLANG_WARN_ENUM_CONVERSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN_UNREACHABLE_CODE = YES; 210 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 211 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 212 | COPY_PHASE_STRIP = NO; 213 | DEBUG_INFORMATION_FORMAT = dwarf; 214 | ENABLE_STRICT_OBJC_MSGSEND = YES; 215 | ENABLE_TESTABILITY = YES; 216 | GCC_C_LANGUAGE_STANDARD = gnu99; 217 | GCC_DYNAMIC_NO_PIC = NO; 218 | GCC_NO_COMMON_BLOCKS = YES; 219 | GCC_OPTIMIZATION_LEVEL = 0; 220 | GCC_PREPROCESSOR_DEFINITIONS = ( 221 | "DEBUG=1", 222 | "$(inherited)", 223 | ); 224 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 225 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 226 | GCC_WARN_UNDECLARED_SELECTOR = YES; 227 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 228 | GCC_WARN_UNUSED_FUNCTION = YES; 229 | GCC_WARN_UNUSED_VARIABLE = YES; 230 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 231 | MTL_ENABLE_DEBUG_INFO = YES; 232 | ONLY_ACTIVE_ARCH = YES; 233 | SDKROOT = iphoneos; 234 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 235 | }; 236 | name = Debug; 237 | }; 238 | 4B5F2C951CECAF5A0001CEFE /* Release */ = { 239 | isa = XCBuildConfiguration; 240 | buildSettings = { 241 | ALWAYS_SEARCH_USER_PATHS = NO; 242 | CLANG_ANALYZER_NONNULL = YES; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_WARN_BOOL_CONVERSION = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_EMPTY_BODY = YES; 251 | CLANG_WARN_ENUM_CONVERSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_NS_ASSERTIONS = NO; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | GCC_C_LANGUAGE_STANDARD = gnu99; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 270 | MTL_ENABLE_DEBUG_INFO = NO; 271 | SDKROOT = iphoneos; 272 | VALIDATE_PRODUCT = YES; 273 | }; 274 | name = Release; 275 | }; 276 | 4B5F2C971CECAF5A0001CEFE /* Debug */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 280 | INFOPLIST_FILE = DraggableViewController/Info.plist; 281 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 282 | PRODUCT_BUNDLE_IDENTIFIER = com.ostatnicky.DraggableViewController; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | }; 285 | name = Debug; 286 | }; 287 | 4B5F2C981CECAF5A0001CEFE /* Release */ = { 288 | isa = XCBuildConfiguration; 289 | buildSettings = { 290 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 291 | INFOPLIST_FILE = DraggableViewController/Info.plist; 292 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 293 | PRODUCT_BUNDLE_IDENTIFIER = com.ostatnicky.DraggableViewController; 294 | PRODUCT_NAME = "$(TARGET_NAME)"; 295 | }; 296 | name = Release; 297 | }; 298 | /* End XCBuildConfiguration section */ 299 | 300 | /* Begin XCConfigurationList section */ 301 | 4B5F2C7F1CECAF590001CEFE /* Build configuration list for PBXProject "DraggableViewController" */ = { 302 | isa = XCConfigurationList; 303 | buildConfigurations = ( 304 | 4B5F2C941CECAF5A0001CEFE /* Debug */, 305 | 4B5F2C951CECAF5A0001CEFE /* Release */, 306 | ); 307 | defaultConfigurationIsVisible = 0; 308 | defaultConfigurationName = Release; 309 | }; 310 | 4B5F2C961CECAF5A0001CEFE /* Build configuration list for PBXNativeTarget "DraggableViewController" */ = { 311 | isa = XCConfigurationList; 312 | buildConfigurations = ( 313 | 4B5F2C971CECAF5A0001CEFE /* Debug */, 314 | 4B5F2C981CECAF5A0001CEFE /* Release */, 315 | ); 316 | defaultConfigurationIsVisible = 0; 317 | }; 318 | /* End XCConfigurationList section */ 319 | }; 320 | rootObject = 4B5F2C7C1CECAF590001CEFE /* Project object */; 321 | } 322 | -------------------------------------------------------------------------------- /DraggableViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DraggableViewController/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DraggableViewController 4 | // 5 | // Created by Jiri Ostatnicky on 18/05/16. 6 | // Copyright © 2016 Jiri Ostatnicky. 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: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // 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. 24 | // 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. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // 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. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /DraggableViewController/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 | } -------------------------------------------------------------------------------- /DraggableViewController/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 | -------------------------------------------------------------------------------- /DraggableViewController/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 | 27 | -------------------------------------------------------------------------------- /DraggableViewController/BaseAnimator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaseAnimator.swift 3 | // DraggableViewController 4 | // 5 | // Created by Jiri Ostatnicky on 18/05/16. 6 | // Copyright © 2016 Jiri Ostatnicky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum ModalAnimatedTransitioningType { 12 | case Present 13 | case Dismiss 14 | } 15 | 16 | class BaseAnimator: NSObject { 17 | 18 | var transitionType: ModalAnimatedTransitioningType = .Present 19 | 20 | func animatePresentingInContext(transitionContext: UIViewControllerContextTransitioning, fromVC: UIViewController, toVC: UIViewController) { 21 | NSException(name:NSInternalInconsistencyException, reason:"\(#function) must be overridden in a subclass/category", userInfo:nil).raise() 22 | } 23 | 24 | func animateDismissingInContext(transitionContext: UIViewControllerContextTransitioning, fromVC: UIViewController, toVC: UIViewController) { 25 | NSException(name:NSInternalInconsistencyException, reason:"\(#function) must be overridden in a subclass/category", userInfo:nil).raise() 26 | } 27 | 28 | } 29 | 30 | extension BaseAnimator: UIViewControllerAnimatedTransitioning { 31 | 32 | func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 33 | let from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) 34 | let to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) 35 | 36 | if let from = from, to = to { 37 | switch transitionType { 38 | case .Present: 39 | animatePresentingInContext(transitionContext, fromVC: from, toVC: to) 40 | case .Dismiss: 41 | animateDismissingInContext(transitionContext, fromVC: from, toVC: to) 42 | } 43 | } 44 | } 45 | 46 | func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { 47 | NSException(name:NSInternalInconsistencyException, reason:"\(#function) must be overridden in a subclass/category", userInfo:nil).raise() 48 | return 0 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /DraggableViewController/BottomBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DummyView.swift 3 | // DraggableViewController 4 | // 5 | // Created by Jiri Ostatnicky on 18/05/16. 6 | // Copyright © 2016 Jiri Ostatnicky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class BottomBar: UIView { 12 | 13 | static let bottomBarHeight: CGFloat = 50 14 | var button: UIButton! 15 | 16 | override init(frame: CGRect) { 17 | super.init(frame: frame) 18 | setupSubview() 19 | } 20 | 21 | required init?(coder aDecoder: NSCoder) { 22 | fatalError("init(coder:) has not been implemented") 23 | } 24 | 25 | func setupSubview() { 26 | self.backgroundColor = UIColor.grayColor() 27 | 28 | button = UIButton() 29 | button.setTitle("Tap or drag me", forState: .Normal) 30 | button.backgroundColor = UIColor.grayColor() 31 | button.translatesAutoresizingMaskIntoConstraints = false 32 | self.addSubview(button) 33 | 34 | self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[button]-|", options: [], metrics: nil, views: ["button": button])) 35 | self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[button]-|", options: [], metrics: nil, views: ["button": button])) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DraggableViewController/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 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /DraggableViewController/MiniToLargeViewAnimator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MiniToLargeViewAnimator.swift 3 | // DraggableViewController 4 | // 5 | // Created by Jiri Ostatnicky on 18/05/16. 6 | // Copyright © 2016 Jiri Ostatnicky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MiniToLargeViewAnimator: BaseAnimator { 12 | 13 | var initialY: CGFloat = 0 14 | 15 | override func animatePresentingInContext(transitionContext: UIViewControllerContextTransitioning, fromVC: UIViewController, toVC: UIViewController) { 16 | 17 | let fromRect = transitionContext.initialFrameForViewController(fromVC) 18 | var toRect = fromRect 19 | toRect.origin.y = toRect.size.height - initialY 20 | 21 | toVC.view.frame = toRect 22 | let container = transitionContext.containerView() 23 | let imageView = fakeMiniView() 24 | 25 | toVC.view.addSubview(imageView) 26 | container?.addSubview(fromVC.view) 27 | container?.addSubview(toVC.view) 28 | 29 | let animOptions: UIViewAnimationOptions = transitionContext.isInteractive() ? [UIViewAnimationOptions.CurveLinear] : [] 30 | 31 | UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, options: animOptions, animations: { 32 | toVC.view.frame = fromRect 33 | imageView.alpha = 0 34 | }) { (finished) in 35 | imageView.removeFromSuperview() 36 | if transitionContext.transitionWasCancelled() { 37 | transitionContext.completeTransition(false) 38 | } else { 39 | transitionContext.completeTransition(true) 40 | } 41 | } 42 | } 43 | 44 | override func animateDismissingInContext(transitionContext: UIViewControllerContextTransitioning, fromVC: UIViewController, toVC: UIViewController) { 45 | 46 | var fromRect = transitionContext.initialFrameForViewController(fromVC) 47 | fromRect.origin.y = fromRect.size.height - initialY 48 | 49 | let imageView = fakeMiniView() 50 | imageView.alpha = 0 51 | fromVC.view.addSubview(imageView) 52 | 53 | let container = transitionContext.containerView() 54 | container?.addSubview(toVC.view) 55 | container?.addSubview(fromVC.view) 56 | 57 | let animOptions: UIViewAnimationOptions = transitionContext.isInteractive() ? [UIViewAnimationOptions.CurveLinear] : [] 58 | 59 | UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, options: animOptions, animations: { 60 | fromVC.view.frame = fromRect 61 | imageView.alpha = 1 62 | }) { (finished) in 63 | imageView.removeFromSuperview() 64 | if transitionContext.transitionWasCancelled() { 65 | transitionContext.completeTransition(false) 66 | } else { 67 | transitionContext.completeTransition(true) 68 | } 69 | } 70 | } 71 | 72 | override func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { 73 | return transitionContext!.isInteractive() ? 0.4 : 0.3 74 | } 75 | 76 | func fakeMiniView() -> UIView { 77 | // Fake a mini view, two ways: 78 | // 1. create a new certain one 79 | // 2. snapshot old one. 80 | 81 | return BottomBar(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.size.width, height: BottomBar.bottomBarHeight)) 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /DraggableViewController/MiniToLargeViewInteractive.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MiniToLargeViewInteractive.swift 3 | // DraggableViewController 4 | // 5 | // Created by Jiri Ostatnicky on 18/05/16. 6 | // Copyright © 2016 Jiri Ostatnicky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MiniToLargeViewInteractive: UIPercentDrivenInteractiveTransition { 12 | 13 | var viewController: UIViewController? 14 | var presentViewController: UIViewController? 15 | var pan: UIPanGestureRecognizer! 16 | 17 | var shouldComplete = false 18 | var lastProgress: CGFloat? 19 | 20 | func attachToViewController(viewController: UIViewController, withView view: UIView, presentViewController: UIViewController?) { 21 | self.viewController = viewController 22 | self.presentViewController = presentViewController 23 | pan = UIPanGestureRecognizer(target: self, action: #selector(self.onPan(_:))) 24 | view.addGestureRecognizer(pan) 25 | } 26 | 27 | func onPan(pan: UIPanGestureRecognizer) { 28 | let translation = pan.translationInView(pan.view?.superview) 29 | 30 | //Represents the percentage of the transition that must be completed before allowing to complete. 31 | let percentThreshold: CGFloat = 0.2 32 | //Represents the difference between progress that is required to trigger the completion of the transition. 33 | let automaticOverrideThreshold: CGFloat = 0.03 34 | 35 | let screenHeight: CGFloat = UIScreen.mainScreen().bounds.size.height - BottomBar.bottomBarHeight 36 | let dragAmount: CGFloat = (presentViewController == nil) ? screenHeight : -screenHeight 37 | var progress: CGFloat = translation.y / dragAmount 38 | 39 | progress = fmax(progress, 0) 40 | progress = fmin(progress, 1) 41 | 42 | switch pan.state { 43 | case .Began: 44 | if let presentViewController = presentViewController { 45 | viewController?.presentViewController(presentViewController, animated: true, completion: nil) 46 | } else { 47 | viewController?.dismissViewControllerAnimated(true, completion: nil) 48 | } 49 | 50 | case .Changed: 51 | guard let lastProgress = lastProgress else {return} 52 | 53 | // When swiping back 54 | if lastProgress > progress { 55 | shouldComplete = false 56 | // When swiping quick to the right 57 | } else if progress > lastProgress + automaticOverrideThreshold { 58 | shouldComplete = true 59 | } else { 60 | // Normal behavior 61 | shouldComplete = progress > percentThreshold 62 | } 63 | updateInteractiveTransition(progress) 64 | 65 | case .Ended, .Cancelled: 66 | if pan.state == .Cancelled || shouldComplete == false { 67 | cancelInteractiveTransition() 68 | } else { 69 | finishInteractiveTransition() 70 | } 71 | 72 | default: 73 | break 74 | } 75 | 76 | lastProgress = progress 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /DraggableViewController/NextViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NextViewController.swift 3 | // DraggableViewController 4 | // 5 | // Created by Jiri Ostatnicky on 18/05/16. 6 | // Copyright © 2016 Jiri Ostatnicky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class NextViewController: UIViewController { 12 | 13 | var rootViewController: ViewController? 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | self.view.backgroundColor = UIColor.brownColor() 18 | 19 | let button = UIButton() 20 | button.setTitle("Dismiss", forState: .Normal) 21 | button.addTarget(self, action: #selector(self.buttonTapped), forControlEvents: .TouchUpInside) 22 | button.translatesAutoresizingMaskIntoConstraints = false 23 | self.view.addSubview(button) 24 | 25 | self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-6-[button]", options: [], metrics: nil, views: ["button": button])) 26 | self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-20-[button]", options: [], metrics: nil, views: ["button": button])) 27 | } 28 | 29 | func buttonTapped() { 30 | rootViewController?.disableInteractivePlayerTransitioning = true 31 | self.dismissViewControllerAnimated(true) { [unowned self] in 32 | self.rootViewController?.disableInteractivePlayerTransitioning = false 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /DraggableViewController/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DraggableViewController 4 | // 5 | // Created by Jiri Ostatnicky on 18/05/16. 6 | // Copyright © 2016 Jiri Ostatnicky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | var disableInteractivePlayerTransitioning = false 14 | 15 | var bottomBar: BottomBar! 16 | var nextViewController: NextViewController! 17 | var presentInteractor: MiniToLargeViewInteractive! 18 | var dismissInteractor: MiniToLargeViewInteractive! 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | 23 | prepareView() 24 | } 25 | 26 | func prepareView() { 27 | bottomBar = BottomBar() 28 | bottomBar.button.addTarget(self, action: #selector(self.bottomButtonTapped), forControlEvents: .TouchUpInside) 29 | bottomBar.translatesAutoresizingMaskIntoConstraints = false 30 | self.view.addSubview(bottomBar) 31 | 32 | self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[bottomBar]-0-|", options: [], metrics: nil, views: ["bottomBar": bottomBar])) 33 | self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[bottomBar(\(BottomBar.bottomBarHeight))]-0-|", options: [], metrics: nil, views: ["bottomBar": bottomBar])) 34 | 35 | nextViewController = NextViewController() 36 | nextViewController.rootViewController = self 37 | nextViewController.transitioningDelegate = self 38 | nextViewController.modalPresentationStyle = .FullScreen 39 | 40 | presentInteractor = MiniToLargeViewInteractive() 41 | presentInteractor.attachToViewController(self, withView: bottomBar, presentViewController: nextViewController) 42 | dismissInteractor = MiniToLargeViewInteractive() 43 | dismissInteractor.attachToViewController(nextViewController, withView: nextViewController.view, presentViewController: nil) 44 | } 45 | 46 | func bottomButtonTapped() { 47 | disableInteractivePlayerTransitioning = true 48 | self.presentViewController(nextViewController, animated: true) { [unowned self] in 49 | self.disableInteractivePlayerTransitioning = false 50 | } 51 | } 52 | 53 | } 54 | 55 | extension ViewController: UIViewControllerTransitioningDelegate { 56 | 57 | func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 58 | let animator = MiniToLargeViewAnimator() 59 | animator.initialY = BottomBar.bottomBarHeight 60 | animator.transitionType = .Present 61 | return animator 62 | } 63 | 64 | func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 65 | let animator = MiniToLargeViewAnimator() 66 | animator.initialY = BottomBar.bottomBarHeight 67 | animator.transitionType = .Dismiss 68 | return animator 69 | } 70 | 71 | func interactionControllerForPresentation(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { 72 | guard !disableInteractivePlayerTransitioning else { return nil } 73 | return presentInteractor 74 | } 75 | 76 | func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { 77 | guard !disableInteractivePlayerTransitioning else { return nil } 78 | return dismissInteractor 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DraggableViewController 2 | 3 | Swift version of Objective-C DraggableViewController in tutorial http://imnotyourson.com/draggable-view-controller-interactive-view-controller/ 4 | 5 | ![DraggableViewController](https://raw.githubusercontent.com/ostatnicky/DraggableViewController/master/draggableViewController.gif) -------------------------------------------------------------------------------- /draggableViewController.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ostatnicky/DraggableViewController/c892061c13d6ff57bbf064fe939533c71a349619/draggableViewController.gif --------------------------------------------------------------------------------