├── .gitignore ├── LICENSE ├── README.md ├── ViewControllerTransitionExample.xcodeproj └── project.pbxproj └── ViewControllerTransitionExample ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── CoolViewController.swift ├── HomeViewController.swift ├── Info.plist ├── SceneDelegate.swift ├── Transitions ├── CustomPresentable.swift ├── InteractionControlling.swift ├── ModalPresentationController.swift ├── ModalTransitionAnimator.swift ├── ModalTransitionManager.swift ├── StandardInteractionController.swift └── UIViewController+Transitions.swift └── Utilities ├── OneWayPanGestureRecognizer.swift └── ViewFactory.swift /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/xcode,macos,swift 3 | # Edit at https://www.gitignore.io/?templates=xcode,macos,swift 4 | 5 | ### macOS ### 6 | # General 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # Icon must end with two \r 12 | Icon 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | .com.apple.timemachine.donotpresent 25 | 26 | # Directories potentially created on remote AFP share 27 | .AppleDB 28 | .AppleDesktop 29 | Network Trash Folder 30 | Temporary Items 31 | .apdisk 32 | 33 | ### Swift ### 34 | # Xcode 35 | # 36 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 37 | 38 | ## Build generated 39 | build/ 40 | DerivedData/ 41 | 42 | ## Various settings 43 | *.pbxuser 44 | !default.pbxuser 45 | *.mode1v3 46 | !default.mode1v3 47 | *.mode2v3 48 | !default.mode2v3 49 | *.perspectivev3 50 | !default.perspectivev3 51 | xcuserdata/ 52 | 53 | ## Other 54 | *.moved-aside 55 | *.xccheckout 56 | *.xcscmblueprint 57 | 58 | ## Obj-C/Swift specific 59 | *.hmap 60 | *.ipa 61 | *.dSYM.zip 62 | *.dSYM 63 | 64 | ## Playgrounds 65 | timeline.xctimeline 66 | playground.xcworkspace 67 | 68 | # Swift Package Manager 69 | # 70 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 71 | # Packages/ 72 | # Package.pins 73 | # Package.resolved 74 | .build/ 75 | 76 | # CocoaPods 77 | # 78 | # We recommend against adding the Pods directory to your .gitignore. However 79 | # you should judge for yourself, the pros and cons are mentioned at: 80 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 81 | # 82 | Pods/ 83 | # 84 | # Add this line if you want to avoid checking in source code from the Xcode workspace 85 | # *.xcworkspace 86 | 87 | # Carthage 88 | # 89 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 90 | # Carthage/Checkouts 91 | 92 | Carthage/Build 93 | 94 | # fastlane 95 | # 96 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 97 | # screenshots whenever they are needed. 98 | # For more information about the recommended setup visit: 99 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 100 | 101 | fastlane/report.xml 102 | fastlane/Preview.html 103 | fastlane/screenshots/**/*.png 104 | fastlane/test_output 105 | 106 | # Code Injection 107 | # 108 | # After new code Injection tools there's a generated folder /iOSInjectionProject 109 | # https://github.com/johnno1962/injectionforxcode 110 | 111 | iOSInjectionProject/ 112 | 113 | ### Xcode ### 114 | # Xcode 115 | # 116 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 117 | 118 | ## User settings 119 | 120 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 121 | 122 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 123 | 124 | ### Xcode Patch ### 125 | *.xcodeproj/* 126 | !*.xcodeproj/project.pbxproj 127 | !*.xcodeproj/xcshareddata/ 128 | !*.xcworkspace/contents.xcworkspacedata 129 | /*.gcno 130 | **/xcshareddata/WorkspaceSettings.xcsettings 131 | 132 | ### Localization ### 133 | vendor/localization/output 134 | 135 | # End of https://www.gitignore.io/api/xcode,macos,swift 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Daniel Gauthier 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🎉 Custom view controller transitions! 🎉 2 | This repo contains a simple working example of a few techniques described at [https://danielgauthier.me](https://danielgauthier.me). 3 | 4 | ![Example gif](https://danielgauthier.me/assets/img/indie-5-3-eg2.gif) 5 | 6 | ## Articles 7 | [Make your custom transitions reusable](https://danielgauthier.me/2020/02/24/indie5-1.html) 8 | 9 | [Make your custom transitions feel natural](https://danielgauthier.me/2020/02/27/indie5-2.html) 10 | 11 | [Make your custom transitions resizable](https://danielgauthier.me/2020/03/03/indie5-3.html) 12 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 65830CF7240EA233004DC2A4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830CF6240EA233004DC2A4 /* AppDelegate.swift */; }; 11 | 65830CF9240EA233004DC2A4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830CF8240EA233004DC2A4 /* SceneDelegate.swift */; }; 12 | 65830CFB240EA233004DC2A4 /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830CFA240EA233004DC2A4 /* HomeViewController.swift */; }; 13 | 65830D00240EA235004DC2A4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65830CFF240EA235004DC2A4 /* Assets.xcassets */; }; 14 | 65830D03240EA235004DC2A4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65830D01240EA235004DC2A4 /* LaunchScreen.storyboard */; }; 15 | 65830D0C240EA361004DC2A4 /* Cartography in Frameworks */ = {isa = PBXBuildFile; productRef = 65830D0B240EA361004DC2A4 /* Cartography */; }; 16 | 65830D0E240EA3A9004DC2A4 /* ViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D0D240EA3A9004DC2A4 /* ViewFactory.swift */; }; 17 | 65830D17240EA4D3004DC2A4 /* ModalTransitionAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D0F240EA4D2004DC2A4 /* ModalTransitionAnimator.swift */; }; 18 | 65830D18240EA4D3004DC2A4 /* InteractionControlling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D10240EA4D2004DC2A4 /* InteractionControlling.swift */; }; 19 | 65830D19240EA4D3004DC2A4 /* CustomPresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D11240EA4D2004DC2A4 /* CustomPresentable.swift */; }; 20 | 65830D1B240EA4D3004DC2A4 /* ModalPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D13240EA4D3004DC2A4 /* ModalPresentationController.swift */; }; 21 | 65830D1C240EA4D3004DC2A4 /* StandardInteractionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D14240EA4D3004DC2A4 /* StandardInteractionController.swift */; }; 22 | 65830D1D240EA4D3004DC2A4 /* UIViewController+Transitions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D15240EA4D3004DC2A4 /* UIViewController+Transitions.swift */; }; 23 | 65830D1E240EA4D3004DC2A4 /* ModalTransitionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D16240EA4D3004DC2A4 /* ModalTransitionManager.swift */; }; 24 | 65830D21240EA615004DC2A4 /* OneWayPanGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D20240EA615004DC2A4 /* OneWayPanGestureRecognizer.swift */; }; 25 | 65830D24240EA6A1004DC2A4 /* CoolViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65830D23240EA6A1004DC2A4 /* CoolViewController.swift */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 65830CF3240EA233004DC2A4 /* ViewControllerTransitionExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ViewControllerTransitionExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 65830CF6240EA233004DC2A4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 31 | 65830CF8240EA233004DC2A4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 32 | 65830CFA240EA233004DC2A4 /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = ""; }; 33 | 65830CFF240EA235004DC2A4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 34 | 65830D02240EA235004DC2A4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 35 | 65830D04240EA235004DC2A4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 36 | 65830D0D240EA3A9004DC2A4 /* ViewFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewFactory.swift; sourceTree = ""; }; 37 | 65830D0F240EA4D2004DC2A4 /* ModalTransitionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalTransitionAnimator.swift; sourceTree = ""; }; 38 | 65830D10240EA4D2004DC2A4 /* InteractionControlling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InteractionControlling.swift; sourceTree = ""; }; 39 | 65830D11240EA4D2004DC2A4 /* CustomPresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomPresentable.swift; sourceTree = ""; }; 40 | 65830D13240EA4D3004DC2A4 /* ModalPresentationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalPresentationController.swift; sourceTree = ""; }; 41 | 65830D14240EA4D3004DC2A4 /* StandardInteractionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardInteractionController.swift; sourceTree = ""; }; 42 | 65830D15240EA4D3004DC2A4 /* UIViewController+Transitions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Transitions.swift"; sourceTree = ""; }; 43 | 65830D16240EA4D3004DC2A4 /* ModalTransitionManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalTransitionManager.swift; sourceTree = ""; }; 44 | 65830D20240EA615004DC2A4 /* OneWayPanGestureRecognizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OneWayPanGestureRecognizer.swift; sourceTree = ""; }; 45 | 65830D23240EA6A1004DC2A4 /* CoolViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoolViewController.swift; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | 65830CF0240EA233004DC2A4 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | 65830D0C240EA361004DC2A4 /* Cartography in Frameworks */, 54 | ); 55 | runOnlyForDeploymentPostprocessing = 0; 56 | }; 57 | /* End PBXFrameworksBuildPhase section */ 58 | 59 | /* Begin PBXGroup section */ 60 | 65830CEA240EA233004DC2A4 = { 61 | isa = PBXGroup; 62 | children = ( 63 | 65830CF5240EA233004DC2A4 /* ViewControllerTransitionExample */, 64 | 65830CF4240EA233004DC2A4 /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 65830CF4240EA233004DC2A4 /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 65830CF3240EA233004DC2A4 /* ViewControllerTransitionExample.app */, 72 | ); 73 | name = Products; 74 | sourceTree = ""; 75 | }; 76 | 65830CF5240EA233004DC2A4 /* ViewControllerTransitionExample */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | 65830CF6240EA233004DC2A4 /* AppDelegate.swift */, 80 | 65830CF8240EA233004DC2A4 /* SceneDelegate.swift */, 81 | 65830CFA240EA233004DC2A4 /* HomeViewController.swift */, 82 | 65830D23240EA6A1004DC2A4 /* CoolViewController.swift */, 83 | 65830D22240EA683004DC2A4 /* Utilities */, 84 | 65830D1F240EA4D9004DC2A4 /* Transitions */, 85 | 65830CFF240EA235004DC2A4 /* Assets.xcassets */, 86 | 65830D01240EA235004DC2A4 /* LaunchScreen.storyboard */, 87 | 65830D04240EA235004DC2A4 /* Info.plist */, 88 | ); 89 | path = ViewControllerTransitionExample; 90 | sourceTree = ""; 91 | }; 92 | 65830D1F240EA4D9004DC2A4 /* Transitions */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 65830D11240EA4D2004DC2A4 /* CustomPresentable.swift */, 96 | 65830D10240EA4D2004DC2A4 /* InteractionControlling.swift */, 97 | 65830D13240EA4D3004DC2A4 /* ModalPresentationController.swift */, 98 | 65830D0F240EA4D2004DC2A4 /* ModalTransitionAnimator.swift */, 99 | 65830D16240EA4D3004DC2A4 /* ModalTransitionManager.swift */, 100 | 65830D14240EA4D3004DC2A4 /* StandardInteractionController.swift */, 101 | 65830D15240EA4D3004DC2A4 /* UIViewController+Transitions.swift */, 102 | ); 103 | path = Transitions; 104 | sourceTree = ""; 105 | }; 106 | 65830D22240EA683004DC2A4 /* Utilities */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 65830D0D240EA3A9004DC2A4 /* ViewFactory.swift */, 110 | 65830D20240EA615004DC2A4 /* OneWayPanGestureRecognizer.swift */, 111 | ); 112 | path = Utilities; 113 | sourceTree = ""; 114 | }; 115 | /* End PBXGroup section */ 116 | 117 | /* Begin PBXNativeTarget section */ 118 | 65830CF2240EA233004DC2A4 /* ViewControllerTransitionExample */ = { 119 | isa = PBXNativeTarget; 120 | buildConfigurationList = 65830D07240EA235004DC2A4 /* Build configuration list for PBXNativeTarget "ViewControllerTransitionExample" */; 121 | buildPhases = ( 122 | 65830CEF240EA233004DC2A4 /* Sources */, 123 | 65830CF0240EA233004DC2A4 /* Frameworks */, 124 | 65830CF1240EA233004DC2A4 /* Resources */, 125 | ); 126 | buildRules = ( 127 | ); 128 | dependencies = ( 129 | ); 130 | name = ViewControllerTransitionExample; 131 | packageProductDependencies = ( 132 | 65830D0B240EA361004DC2A4 /* Cartography */, 133 | ); 134 | productName = ViewControllerTransitionExample; 135 | productReference = 65830CF3240EA233004DC2A4 /* ViewControllerTransitionExample.app */; 136 | productType = "com.apple.product-type.application"; 137 | }; 138 | /* End PBXNativeTarget section */ 139 | 140 | /* Begin PBXProject section */ 141 | 65830CEB240EA233004DC2A4 /* Project object */ = { 142 | isa = PBXProject; 143 | attributes = { 144 | LastSwiftUpdateCheck = 1120; 145 | LastUpgradeCheck = 1120; 146 | ORGANIZATIONNAME = "Daniel Gauthier"; 147 | TargetAttributes = { 148 | 65830CF2240EA233004DC2A4 = { 149 | CreatedOnToolsVersion = 11.2.1; 150 | }; 151 | }; 152 | }; 153 | buildConfigurationList = 65830CEE240EA233004DC2A4 /* Build configuration list for PBXProject "ViewControllerTransitionExample" */; 154 | compatibilityVersion = "Xcode 9.3"; 155 | developmentRegion = en; 156 | hasScannedForEncodings = 0; 157 | knownRegions = ( 158 | en, 159 | Base, 160 | ); 161 | mainGroup = 65830CEA240EA233004DC2A4; 162 | packageReferences = ( 163 | 65830D0A240EA361004DC2A4 /* XCRemoteSwiftPackageReference "Cartography" */, 164 | ); 165 | productRefGroup = 65830CF4240EA233004DC2A4 /* Products */; 166 | projectDirPath = ""; 167 | projectRoot = ""; 168 | targets = ( 169 | 65830CF2240EA233004DC2A4 /* ViewControllerTransitionExample */, 170 | ); 171 | }; 172 | /* End PBXProject section */ 173 | 174 | /* Begin PBXResourcesBuildPhase section */ 175 | 65830CF1240EA233004DC2A4 /* Resources */ = { 176 | isa = PBXResourcesBuildPhase; 177 | buildActionMask = 2147483647; 178 | files = ( 179 | 65830D03240EA235004DC2A4 /* LaunchScreen.storyboard in Resources */, 180 | 65830D00240EA235004DC2A4 /* Assets.xcassets in Resources */, 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXResourcesBuildPhase section */ 185 | 186 | /* Begin PBXSourcesBuildPhase section */ 187 | 65830CEF240EA233004DC2A4 /* Sources */ = { 188 | isa = PBXSourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | 65830CFB240EA233004DC2A4 /* HomeViewController.swift in Sources */, 192 | 65830D1C240EA4D3004DC2A4 /* StandardInteractionController.swift in Sources */, 193 | 65830D1E240EA4D3004DC2A4 /* ModalTransitionManager.swift in Sources */, 194 | 65830D17240EA4D3004DC2A4 /* ModalTransitionAnimator.swift in Sources */, 195 | 65830D1D240EA4D3004DC2A4 /* UIViewController+Transitions.swift in Sources */, 196 | 65830D19240EA4D3004DC2A4 /* CustomPresentable.swift in Sources */, 197 | 65830CF7240EA233004DC2A4 /* AppDelegate.swift in Sources */, 198 | 65830D1B240EA4D3004DC2A4 /* ModalPresentationController.swift in Sources */, 199 | 65830D21240EA615004DC2A4 /* OneWayPanGestureRecognizer.swift in Sources */, 200 | 65830D0E240EA3A9004DC2A4 /* ViewFactory.swift in Sources */, 201 | 65830D18240EA4D3004DC2A4 /* InteractionControlling.swift in Sources */, 202 | 65830CF9240EA233004DC2A4 /* SceneDelegate.swift in Sources */, 203 | 65830D24240EA6A1004DC2A4 /* CoolViewController.swift in Sources */, 204 | ); 205 | runOnlyForDeploymentPostprocessing = 0; 206 | }; 207 | /* End PBXSourcesBuildPhase section */ 208 | 209 | /* Begin PBXVariantGroup section */ 210 | 65830D01240EA235004DC2A4 /* LaunchScreen.storyboard */ = { 211 | isa = PBXVariantGroup; 212 | children = ( 213 | 65830D02240EA235004DC2A4 /* Base */, 214 | ); 215 | name = LaunchScreen.storyboard; 216 | sourceTree = ""; 217 | }; 218 | /* End PBXVariantGroup section */ 219 | 220 | /* Begin XCBuildConfiguration section */ 221 | 65830D05240EA235004DC2A4 /* Debug */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | ALWAYS_SEARCH_USER_PATHS = NO; 225 | CLANG_ANALYZER_NONNULL = YES; 226 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_ENABLE_OBJC_WEAK = YES; 232 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 233 | CLANG_WARN_BOOL_CONVERSION = YES; 234 | CLANG_WARN_COMMA = YES; 235 | CLANG_WARN_CONSTANT_CONVERSION = YES; 236 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 237 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 238 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 239 | CLANG_WARN_EMPTY_BODY = YES; 240 | CLANG_WARN_ENUM_CONVERSION = YES; 241 | CLANG_WARN_INFINITE_RECURSION = YES; 242 | CLANG_WARN_INT_CONVERSION = YES; 243 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 244 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 245 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 246 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 247 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 248 | CLANG_WARN_STRICT_PROTOTYPES = YES; 249 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 250 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 251 | CLANG_WARN_UNREACHABLE_CODE = YES; 252 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 253 | COPY_PHASE_STRIP = NO; 254 | DEBUG_INFORMATION_FORMAT = dwarf; 255 | ENABLE_STRICT_OBJC_MSGSEND = YES; 256 | ENABLE_TESTABILITY = YES; 257 | GCC_C_LANGUAGE_STANDARD = gnu11; 258 | GCC_DYNAMIC_NO_PIC = NO; 259 | GCC_NO_COMMON_BLOCKS = YES; 260 | GCC_OPTIMIZATION_LEVEL = 0; 261 | GCC_PREPROCESSOR_DEFINITIONS = ( 262 | "DEBUG=1", 263 | "$(inherited)", 264 | ); 265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 267 | GCC_WARN_UNDECLARED_SELECTOR = YES; 268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 269 | GCC_WARN_UNUSED_FUNCTION = YES; 270 | GCC_WARN_UNUSED_VARIABLE = YES; 271 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 272 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 273 | MTL_FAST_MATH = YES; 274 | ONLY_ACTIVE_ARCH = YES; 275 | SDKROOT = iphoneos; 276 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 277 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 278 | }; 279 | name = Debug; 280 | }; 281 | 65830D06240EA235004DC2A4 /* Release */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ALWAYS_SEARCH_USER_PATHS = NO; 285 | CLANG_ANALYZER_NONNULL = YES; 286 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 287 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 288 | CLANG_CXX_LIBRARY = "libc++"; 289 | CLANG_ENABLE_MODULES = YES; 290 | CLANG_ENABLE_OBJC_ARC = YES; 291 | CLANG_ENABLE_OBJC_WEAK = YES; 292 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 293 | CLANG_WARN_BOOL_CONVERSION = YES; 294 | CLANG_WARN_COMMA = YES; 295 | CLANG_WARN_CONSTANT_CONVERSION = YES; 296 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 297 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 298 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 299 | CLANG_WARN_EMPTY_BODY = YES; 300 | CLANG_WARN_ENUM_CONVERSION = YES; 301 | CLANG_WARN_INFINITE_RECURSION = YES; 302 | CLANG_WARN_INT_CONVERSION = YES; 303 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 304 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 305 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 306 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 307 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 308 | CLANG_WARN_STRICT_PROTOTYPES = YES; 309 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 310 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 311 | CLANG_WARN_UNREACHABLE_CODE = YES; 312 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 313 | COPY_PHASE_STRIP = NO; 314 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 315 | ENABLE_NS_ASSERTIONS = NO; 316 | ENABLE_STRICT_OBJC_MSGSEND = YES; 317 | GCC_C_LANGUAGE_STANDARD = gnu11; 318 | GCC_NO_COMMON_BLOCKS = YES; 319 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 320 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 321 | GCC_WARN_UNDECLARED_SELECTOR = YES; 322 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 323 | GCC_WARN_UNUSED_FUNCTION = YES; 324 | GCC_WARN_UNUSED_VARIABLE = YES; 325 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 326 | MTL_ENABLE_DEBUG_INFO = NO; 327 | MTL_FAST_MATH = YES; 328 | SDKROOT = iphoneos; 329 | SWIFT_COMPILATION_MODE = wholemodule; 330 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 331 | VALIDATE_PRODUCT = YES; 332 | }; 333 | name = Release; 334 | }; 335 | 65830D08240EA235004DC2A4 /* Debug */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 339 | CODE_SIGN_STYLE = Automatic; 340 | DEVELOPMENT_TEAM = 225N53A79M; 341 | INFOPLIST_FILE = ViewControllerTransitionExample/Info.plist; 342 | LD_RUNPATH_SEARCH_PATHS = ( 343 | "$(inherited)", 344 | "@executable_path/Frameworks", 345 | ); 346 | PRODUCT_BUNDLE_IDENTIFIER = com.bandithat.ViewControllerTransitionExample; 347 | PRODUCT_NAME = "$(TARGET_NAME)"; 348 | SWIFT_VERSION = 5.0; 349 | TARGETED_DEVICE_FAMILY = "1,2"; 350 | }; 351 | name = Debug; 352 | }; 353 | 65830D09240EA235004DC2A4 /* Release */ = { 354 | isa = XCBuildConfiguration; 355 | buildSettings = { 356 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 357 | CODE_SIGN_STYLE = Automatic; 358 | DEVELOPMENT_TEAM = 225N53A79M; 359 | INFOPLIST_FILE = ViewControllerTransitionExample/Info.plist; 360 | LD_RUNPATH_SEARCH_PATHS = ( 361 | "$(inherited)", 362 | "@executable_path/Frameworks", 363 | ); 364 | PRODUCT_BUNDLE_IDENTIFIER = com.bandithat.ViewControllerTransitionExample; 365 | PRODUCT_NAME = "$(TARGET_NAME)"; 366 | SWIFT_VERSION = 5.0; 367 | TARGETED_DEVICE_FAMILY = "1,2"; 368 | }; 369 | name = Release; 370 | }; 371 | /* End XCBuildConfiguration section */ 372 | 373 | /* Begin XCConfigurationList section */ 374 | 65830CEE240EA233004DC2A4 /* Build configuration list for PBXProject "ViewControllerTransitionExample" */ = { 375 | isa = XCConfigurationList; 376 | buildConfigurations = ( 377 | 65830D05240EA235004DC2A4 /* Debug */, 378 | 65830D06240EA235004DC2A4 /* Release */, 379 | ); 380 | defaultConfigurationIsVisible = 0; 381 | defaultConfigurationName = Release; 382 | }; 383 | 65830D07240EA235004DC2A4 /* Build configuration list for PBXNativeTarget "ViewControllerTransitionExample" */ = { 384 | isa = XCConfigurationList; 385 | buildConfigurations = ( 386 | 65830D08240EA235004DC2A4 /* Debug */, 387 | 65830D09240EA235004DC2A4 /* Release */, 388 | ); 389 | defaultConfigurationIsVisible = 0; 390 | defaultConfigurationName = Release; 391 | }; 392 | /* End XCConfigurationList section */ 393 | 394 | /* Begin XCRemoteSwiftPackageReference section */ 395 | 65830D0A240EA361004DC2A4 /* XCRemoteSwiftPackageReference "Cartography" */ = { 396 | isa = XCRemoteSwiftPackageReference; 397 | repositoryURL = "https://github.com/robb/Cartography.git"; 398 | requirement = { 399 | kind = upToNextMajorVersion; 400 | minimumVersion = 4.0.0; 401 | }; 402 | }; 403 | /* End XCRemoteSwiftPackageReference section */ 404 | 405 | /* Begin XCSwiftPackageProductDependency section */ 406 | 65830D0B240EA361004DC2A4 /* Cartography */ = { 407 | isa = XCSwiftPackageProductDependency; 408 | package = 65830D0A240EA361004DC2A4 /* XCRemoteSwiftPackageReference "Cartography" */; 409 | productName = Cartography; 410 | }; 411 | /* End XCSwiftPackageProductDependency section */ 412 | }; 413 | rootObject = 65830CEB240EA233004DC2A4 /* Project object */; 414 | } 415 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | 6 | 7 | 8 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 9 | return true 10 | } 11 | 12 | // MARK: UISceneSession Lifecycle 13 | 14 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 15 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 16 | } 17 | 18 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) {} 19 | } 20 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/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 | } -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ViewControllerTransitionExample/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 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/CoolViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Cartography 3 | 4 | class CoolViewController: UIViewController, CustomPresentable { 5 | var transitionManager: UIViewControllerTransitioningDelegate? 6 | 7 | let rectangleView: UIView = .make(backgroundColor: UIColor.systemPink.withAlphaComponent(0.5), cornerRadius: 12.0) 8 | 9 | let sizeButton: UIButton = .make( 10 | contentColor: .white, 11 | backgroundColor: .systemPink, 12 | title: "Change rectangle size!", 13 | textFormat: (17.0, .bold), 14 | height: 50, 15 | cornerRadius: 25, 16 | padding: 16 17 | ) 18 | 19 | let dismissButton: UIButton = .make( 20 | contentColor: .systemPink, 21 | backgroundColor: .clear, 22 | title: "Dismiss", 23 | textFormat: (17.0, .bold), 24 | height: 50, 25 | cornerRadius: 25, 26 | padding: 16, 27 | style: .outline 28 | ) 29 | 30 | var rectangleHeightConstraint: NSLayoutConstraint! 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | view.backgroundColor = .systemBackground 35 | view.layer.cornerRadius = 20.0 36 | view.addSubview(rectangleView) 37 | view.addSubview(sizeButton) 38 | view.addSubview(dismissButton) 39 | 40 | constrain(rectangleView) { 41 | $0.top == $0.superview!.top + 16.0 42 | $0.leading == $0.superview!.leading + 16.0 43 | $0.trailing == $0.superview!.trailing - 16.0 44 | rectangleHeightConstraint = ($0.height == 100.0) 45 | } 46 | 47 | constrain(sizeButton, rectangleView) { 48 | $0.top == $1.bottom + 16.0 49 | $0.centerX == $0.superview!.centerX 50 | } 51 | 52 | constrain(dismissButton, sizeButton) { 53 | $0.top == $1.bottom + 16.0 54 | $0.width == $1.width 55 | $0.centerX == $1.centerX 56 | $0.bottom == $0.superview!.bottom - 16.0 ~ .init(999) 57 | } 58 | 59 | sizeButton.addTarget(self, action: #selector(sizeButtonTapped), for: .touchUpInside) 60 | dismissButton.addTarget(self, action: #selector(dismissButtonTapped), for: .touchUpInside) 61 | } 62 | 63 | @objc private func dismissButtonTapped() { 64 | dismiss(animated: true) 65 | } 66 | 67 | @objc private func sizeButtonTapped() { 68 | rectangleHeightConstraint.constant = CGFloat(Int.random(in: 50...400)) 69 | updatePresentationLayout(animated: true) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/HomeViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Cartography 3 | 4 | final class HomeViewController: UIViewController { 5 | 6 | let presentButton: UIButton = .make(contentColor: .white, 7 | backgroundColor: .systemPink, 8 | title: "Present the thing!", 9 | textFormat: (17.0, .bold), 10 | height: 50.0, 11 | cornerRadius: 25.0, 12 | padding: 16.0) 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | view.backgroundColor = .systemBackground 17 | view.addSubview(presentButton) 18 | constrain(presentButton) { 19 | $0.center == $0.superview!.center 20 | } 21 | 22 | presentButton.addTarget(self, action: #selector(presentButtonTapped), for: .touchUpInside) 23 | } 24 | 25 | @objc private func presentButtonTapped() { 26 | let coolViewController = CoolViewController() 27 | present(coolViewController, interactiveDismissalType: .standard) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/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 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 4 | 5 | var window: UIWindow? 6 | var homeViewController: HomeViewController! 7 | 8 | 9 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 10 | 11 | homeViewController = HomeViewController() 12 | 13 | if let windowScene = scene as? UIWindowScene { 14 | let window = UIWindow(windowScene: windowScene) 15 | window.rootViewController = homeViewController 16 | self.window = window 17 | window.makeKeyAndVisible() 18 | } 19 | } 20 | 21 | func sceneDidDisconnect(_ scene: UIScene) {} 22 | func sceneDidBecomeActive(_ scene: UIScene) {} 23 | func sceneWillResignActive(_ scene: UIScene) {} 24 | func sceneWillEnterForeground(_ scene: UIScene) {} 25 | func sceneDidEnterBackground(_ scene: UIScene) {} 26 | } 27 | 28 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Transitions/CustomPresentable.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | protocol CustomPresentable: UIViewController { 4 | var transitionManager: UIViewControllerTransitioningDelegate? { get set } 5 | var dismissalHandlingScrollView: UIScrollView? { get } 6 | func updatePresentationLayout(animated: Bool) 7 | } 8 | 9 | extension CustomPresentable { 10 | var dismissalHandlingScrollView: UIScrollView? { nil } 11 | 12 | func updatePresentationLayout(animated: Bool = false) { 13 | presentationController?.containerView?.setNeedsLayout() 14 | if animated { 15 | UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: .allowUserInteraction, animations: { 16 | self.presentationController?.containerView?.layoutIfNeeded() 17 | }, completion: nil) 18 | } else { 19 | presentationController?.containerView?.layoutIfNeeded() 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Transitions/InteractionControlling.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | protocol InteractionControlling: UIViewControllerInteractiveTransitioning { 4 | var interactionInProgress: Bool { get } 5 | } 6 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Transitions/ModalPresentationController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Cartography 3 | 4 | class ModalPresentationController: UIPresentationController { 5 | 6 | lazy var fadeView: UIView = .make(backgroundColor: UIColor.black.withAlphaComponent(0.3), alpha: 0.0) 7 | 8 | override func presentationTransitionWillBegin() { 9 | guard let containerView = containerView else { return } 10 | containerView.insertSubview(fadeView, at: 0) 11 | 12 | constrain(fadeView) { 13 | $0.edges == $0.superview!.edges 14 | } 15 | 16 | guard let coordinator = presentedViewController.transitionCoordinator else { 17 | fadeView.alpha = 1.0 18 | return 19 | } 20 | 21 | coordinator.animate(alongsideTransition: { _ in 22 | self.fadeView.alpha = 1.0 23 | }) 24 | } 25 | 26 | override func dismissalTransitionWillBegin() { 27 | guard let coordinator = presentedViewController.transitionCoordinator else { 28 | fadeView.alpha = 0.0 29 | return 30 | } 31 | 32 | if !coordinator.isInteractive { 33 | coordinator.animate(alongsideTransition: { _ in 34 | self.fadeView.alpha = 0.0 35 | }) 36 | } 37 | } 38 | 39 | override func containerViewWillLayoutSubviews() { 40 | presentedView?.frame = frameOfPresentedViewInContainerView 41 | } 42 | 43 | override var frameOfPresentedViewInContainerView: CGRect { 44 | guard let containerView = containerView, let presentedView = presentedView else { return .zero } 45 | 46 | let inset: CGFloat = 16 47 | let safeAreaFrame = containerView.bounds.inset(by: containerView.safeAreaInsets) 48 | 49 | let targetWidth = safeAreaFrame.width - 2 * inset 50 | let fittingSize = CGSize( 51 | width: targetWidth, 52 | height: UIView.layoutFittingCompressedSize.height 53 | ) 54 | 55 | let targetHeight = presentedView.systemLayoutSizeFitting( 56 | fittingSize, 57 | withHorizontalFittingPriority: .required, 58 | verticalFittingPriority: .defaultLow 59 | ).height 60 | 61 | var frame = safeAreaFrame 62 | frame.origin.x += inset 63 | frame.origin.y += 8.0 64 | frame.size.width = targetWidth 65 | frame.size.height = targetHeight 66 | 67 | return frame 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Transitions/ModalTransitionAnimator.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ModalTransitionAnimator: NSObject { 4 | 5 | private let presenting: Bool 6 | 7 | init(presenting: Bool) { 8 | self.presenting = presenting 9 | super.init() 10 | } 11 | } 12 | 13 | extension ModalTransitionAnimator: UIViewControllerAnimatedTransitioning { 14 | 15 | func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 0.5 } 16 | 17 | func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 18 | if presenting { 19 | animatePresentation(using: transitionContext) 20 | } else { 21 | animateDismissal(using: transitionContext) 22 | } 23 | } 24 | 25 | private func animatePresentation(using transitionContext: UIViewControllerContextTransitioning) { 26 | let presentedViewController = transitionContext.viewController(forKey: .to)! 27 | transitionContext.containerView.addSubview(presentedViewController.view) 28 | 29 | let presentedFrame = transitionContext.finalFrame(for: presentedViewController) 30 | let dismissedFrame = CGRect(x: presentedFrame.minX, y: transitionContext.containerView.bounds.height, width: presentedFrame.width, height: presentedFrame.height) 31 | 32 | presentedViewController.view.frame = dismissedFrame 33 | 34 | let animator = UIViewPropertyAnimator(duration: transitionDuration(using: transitionContext), dampingRatio: 1.0) { 35 | presentedViewController.view.frame = presentedFrame 36 | } 37 | 38 | animator.addCompletion { _ in 39 | transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 40 | } 41 | 42 | animator.startAnimation() 43 | } 44 | 45 | private func animateDismissal(using transitionContext: UIViewControllerContextTransitioning) { 46 | let presentedViewController = transitionContext.viewController(forKey: .from)! 47 | let presentedFrame = transitionContext.finalFrame(for: presentedViewController) 48 | let dismissedFrame = CGRect(x: presentedFrame.minX, y: transitionContext.containerView.bounds.height, width: presentedFrame.width, height: presentedFrame.height) 49 | 50 | let animator = UIViewPropertyAnimator(duration: transitionDuration(using: transitionContext), dampingRatio: 1.0) { 51 | presentedViewController.view.frame = dismissedFrame 52 | } 53 | 54 | animator.addCompletion { _ in 55 | transitionContext.completeTransition(!transitionContext.transitionWasCancelled) 56 | } 57 | 58 | animator.startAnimation() 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Transitions/ModalTransitionManager.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ModalTransitionManager: NSObject { 4 | 5 | private var interactionController: InteractionControlling? 6 | 7 | init(interactionController: InteractionControlling?) { 8 | self.interactionController = interactionController 9 | } 10 | } 11 | 12 | extension ModalTransitionManager: UIViewControllerTransitioningDelegate { 13 | 14 | func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { 15 | return ModalPresentationController(presentedViewController: presented, presenting: presenting) 16 | } 17 | 18 | func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 19 | return ModalTransitionAnimator(presenting: true) 20 | } 21 | 22 | func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 23 | return ModalTransitionAnimator(presenting: false) 24 | } 25 | 26 | func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { 27 | guard let interactionController = interactionController, interactionController.interactionInProgress else { 28 | return nil 29 | } 30 | return interactionController 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Transitions/StandardInteractionController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class StandardInteractionController: NSObject, InteractionControlling { 4 | var interactionInProgress = false 5 | private weak var viewController: CustomPresentable! 6 | private weak var transitionContext: UIViewControllerContextTransitioning? 7 | 8 | private var interactionDistance: CGFloat = 0 9 | private var interruptedTranslation: CGFloat = 0 10 | private var presentedFrame: CGRect? 11 | private var cancellationAnimator: UIViewPropertyAnimator? 12 | 13 | // MARK: - Setup 14 | init(viewController: CustomPresentable) { 15 | self.viewController = viewController 16 | super.init() 17 | prepareGestureRecognizer(in: viewController.view) 18 | if let scrollView = viewController.dismissalHandlingScrollView { 19 | resolveScrollViewGestures(scrollView) 20 | } 21 | } 22 | 23 | private func prepareGestureRecognizer(in view: UIView) { 24 | let gesture = OneWayPanGestureRecognizer(target: self, action: #selector(handleGesture(_:))) 25 | view.addGestureRecognizer(gesture) 26 | } 27 | 28 | private func resolveScrollViewGestures(_ scrollView: UIScrollView) { 29 | let scrollGestureRecognizer = OneWayPanGestureRecognizer(target: self, action: #selector(handleGesture(_:))) 30 | scrollGestureRecognizer.delegate = self 31 | 32 | scrollView.addGestureRecognizer(scrollGestureRecognizer) 33 | scrollView.panGestureRecognizer.require(toFail: scrollGestureRecognizer) 34 | } 35 | 36 | // MARK: - Gesture handling 37 | @objc func handleGesture(_ gestureRecognizer: OneWayPanGestureRecognizer) { 38 | guard let superview = gestureRecognizer.view?.superview else { return } 39 | let translation = gestureRecognizer.translation(in: superview).y 40 | let velocity = gestureRecognizer.velocity(in: superview).y 41 | 42 | switch gestureRecognizer.state { 43 | case .began: gestureBegan() 44 | case .changed: gestureChanged(translation: translation + interruptedTranslation, velocity: velocity) 45 | case .cancelled: gestureCancelled(translation: translation + interruptedTranslation, velocity: velocity) 46 | case .ended: gestureEnded(translation: translation + interruptedTranslation, velocity: velocity) 47 | default: break 48 | } 49 | } 50 | 51 | private func gestureBegan() { 52 | disableOtherTouches() 53 | cancellationAnimator?.stopAnimation(true) 54 | 55 | if let presentedFrame = presentedFrame { 56 | interruptedTranslation = viewController.view.frame.minY - presentedFrame.minY 57 | } 58 | 59 | if !interactionInProgress { 60 | interactionInProgress = true 61 | viewController.dismiss(animated: true) 62 | } 63 | } 64 | 65 | private func gestureChanged(translation: CGFloat, velocity: CGFloat) { 66 | var progress = interactionDistance == 0 ? 0 : (translation / interactionDistance) 67 | if progress < 0 { progress /= (1.0 + abs(progress * 20)) } 68 | update(progress: progress) 69 | } 70 | 71 | private func gestureCancelled(translation: CGFloat, velocity: CGFloat) { 72 | cancel(initialSpringVelocity: springVelocity(distanceToTravel: -translation, gestureVelocity: velocity)) 73 | } 74 | 75 | private func gestureEnded(translation: CGFloat, velocity: CGFloat) { 76 | if velocity > 300 || (translation > interactionDistance / 2.0 && velocity > -300) { 77 | finish(initialSpringVelocity: springVelocity(distanceToTravel: interactionDistance - translation, gestureVelocity: velocity)) 78 | } else { 79 | cancel(initialSpringVelocity: springVelocity(distanceToTravel: -translation, gestureVelocity: velocity)) 80 | } 81 | } 82 | 83 | // MARK: - Transition controlling 84 | func startInteractiveTransition(_ transitionContext: UIViewControllerContextTransitioning) { 85 | let presentedViewController = transitionContext.viewController(forKey: .from)! 86 | presentedFrame = transitionContext.finalFrame(for: presentedViewController) 87 | self.transitionContext = transitionContext 88 | interactionDistance = transitionContext.containerView.bounds.height - presentedFrame!.minY 89 | } 90 | 91 | func update(progress: CGFloat) { 92 | guard let transitionContext = transitionContext, let presentedFrame = presentedFrame else { return } 93 | transitionContext.updateInteractiveTransition(progress) 94 | let presentedViewController = transitionContext.viewController(forKey: .from)! 95 | presentedViewController.view.frame = CGRect(x: presentedFrame.minX, y: presentedFrame.minY + interactionDistance * progress, width: presentedFrame.width, height: presentedFrame.height) 96 | 97 | if let modalPresentationController = presentedViewController.presentationController as? ModalPresentationController { 98 | modalPresentationController.fadeView.alpha = 1.0 - progress 99 | } 100 | } 101 | 102 | func cancel(initialSpringVelocity: CGFloat) { 103 | guard let transitionContext = transitionContext, let presentedFrame = presentedFrame else { return } 104 | let presentedViewController = transitionContext.viewController(forKey: .from)! 105 | 106 | let timingParameters = UISpringTimingParameters(dampingRatio: 0.8, initialVelocity: CGVector(dx: 0, dy: initialSpringVelocity)) 107 | cancellationAnimator = UIViewPropertyAnimator(duration: 0.5, timingParameters: timingParameters) 108 | 109 | cancellationAnimator?.addAnimations { 110 | presentedViewController.view.frame = presentedFrame 111 | if let modalPresentationController = presentedViewController.presentationController as? ModalPresentationController { 112 | modalPresentationController.fadeView.alpha = 1.0 113 | } 114 | } 115 | 116 | cancellationAnimator?.addCompletion { _ in 117 | transitionContext.cancelInteractiveTransition() 118 | transitionContext.completeTransition(false) 119 | self.interactionInProgress = false 120 | self.enableOtherTouches() 121 | } 122 | 123 | cancellationAnimator?.startAnimation() 124 | } 125 | 126 | func finish(initialSpringVelocity: CGFloat) { 127 | guard let transitionContext = transitionContext, let presentedFrame = presentedFrame else { return } 128 | let presentedViewController = transitionContext.viewController(forKey: .from) as! CustomPresentable 129 | let dismissedFrame = CGRect(x: presentedFrame.minX, y: transitionContext.containerView.bounds.height, width: presentedFrame.width, height: presentedFrame.height) 130 | 131 | let timingParameters = UISpringTimingParameters(dampingRatio: 0.8, initialVelocity: CGVector(dx: 0, dy: initialSpringVelocity)) 132 | let finishAnimator = UIViewPropertyAnimator(duration: 0.5, timingParameters: timingParameters) 133 | 134 | finishAnimator.addAnimations { 135 | presentedViewController.view.frame = dismissedFrame 136 | if let modalPresentationController = presentedViewController.presentationController as? ModalPresentationController { 137 | modalPresentationController.fadeView.alpha = 0.0 138 | } 139 | } 140 | 141 | finishAnimator.addCompletion { _ in 142 | transitionContext.finishInteractiveTransition() 143 | transitionContext.completeTransition(true) 144 | self.interactionInProgress = false 145 | } 146 | 147 | finishAnimator.startAnimation() 148 | } 149 | 150 | // MARK: - Helpers 151 | private func springVelocity(distanceToTravel: CGFloat, gestureVelocity: CGFloat) -> CGFloat { 152 | distanceToTravel == 0 ? 0 : gestureVelocity / distanceToTravel 153 | } 154 | 155 | private func disableOtherTouches() { 156 | viewController.view.subviews.forEach { 157 | $0.isUserInteractionEnabled = false 158 | } 159 | } 160 | 161 | private func enableOtherTouches() { 162 | viewController.view.subviews.forEach { 163 | $0.isUserInteractionEnabled = true 164 | } 165 | } 166 | } 167 | 168 | // MARK: - UIGestureRecognizerDelegate 169 | extension StandardInteractionController: UIGestureRecognizerDelegate { 170 | func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { 171 | if let scrollView = viewController.dismissalHandlingScrollView { 172 | return scrollView.contentOffset.y <= 0 173 | } 174 | return true 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Transitions/UIViewController+Transitions.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | enum InteractiveDismissalType { 4 | case none 5 | case standard 6 | } 7 | 8 | extension UIViewController { 9 | func present(_ viewController: CustomPresentable, interactiveDismissalType: InteractiveDismissalType, completion: (() -> Void)? = nil) { 10 | 11 | let interactionController: InteractionControlling? 12 | switch interactiveDismissalType { 13 | case .none: 14 | interactionController = nil 15 | case .standard: 16 | interactionController = StandardInteractionController(viewController: viewController) 17 | } 18 | 19 | let transitionManager = ModalTransitionManager(interactionController: interactionController) 20 | viewController.transitionManager = transitionManager 21 | viewController.transitioningDelegate = transitionManager 22 | viewController.modalPresentationStyle = .custom 23 | present(viewController, animated: true, completion: completion) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Utilities/OneWayPanGestureRecognizer.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | enum OneWayPanGestureDirection { 4 | case up 5 | case down 6 | } 7 | 8 | class OneWayPanGestureRecognizer: UIPanGestureRecognizer { 9 | var drag: Bool = false 10 | var moveX: Int = 0 11 | var moveY: Int = 0 12 | var direction: OneWayPanGestureDirection = .down 13 | 14 | override func touchesMoved(_ touches: Set, with event: UIEvent) { 15 | super.touchesMoved(touches, with: event) 16 | 17 | if state == .failed { 18 | return 19 | } 20 | 21 | let touch: UITouch = touches.first! as UITouch 22 | let nowPoint: CGPoint = touch.location(in: view) 23 | let prevPoint: CGPoint = touch.previousLocation(in: view) 24 | moveX += Int(prevPoint.x - nowPoint.x) 25 | moveY += Int(prevPoint.y - nowPoint.y) 26 | 27 | if !drag { 28 | if moveY == 0 { 29 | drag = false 30 | } else if (direction == .down && moveY > 0) || (direction == .up && moveY < 0) { 31 | state = .failed 32 | } else { 33 | drag = true 34 | } 35 | } 36 | } 37 | 38 | override func reset() { 39 | super.reset() 40 | drag = false 41 | moveX = 0 42 | moveY = 0 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ViewControllerTransitionExample/Utilities/ViewFactory.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | enum ButtonStyle { 4 | case standard 5 | case outline 6 | } 7 | 8 | extension UIButton { 9 | static func make(image: UIImage? = nil, 10 | contentColor: UIColor? = nil, 11 | backgroundColor: UIColor = .clear, 12 | title: String? = nil, 13 | textFormat: (size: CGFloat, weight: UIFont.Weight)? = nil, 14 | width: CGFloat? = nil, 15 | height: CGFloat? = nil, 16 | cornerRadius: CGFloat = 0.0, 17 | padding: CGFloat = 0, 18 | style: ButtonStyle = .standard, 19 | targetSelector: (target: Any, action: Selector)? = nil) -> UIButton { 20 | 21 | let button = UIButton(type: .system) 22 | button.translatesAutoresizingMaskIntoConstraints = false 23 | if let image = image { button.setImage(image, for: .normal) } 24 | if let contentColor = contentColor { 25 | button.tintColor = contentColor 26 | button.setTitleColor(contentColor, for: .normal) 27 | } 28 | button.backgroundColor = backgroundColor 29 | if let title = title { button.setTitle(title, for: .normal) } 30 | if let textFormat = textFormat { 31 | button.titleLabel?.font = UIFont.systemFont(ofSize: textFormat.size, weight: textFormat.weight) 32 | } 33 | 34 | if let width = width { button.widthAnchor.constraint(equalToConstant: width).isActive = true } 35 | if let height = height { button.heightAnchor.constraint(equalToConstant: height).isActive = true } 36 | button.layer.cornerRadius = cornerRadius 37 | button.contentEdgeInsets = UIEdgeInsets(top: 0.0, left: padding, bottom: 0.0, right: padding) 38 | if let targetSelector = targetSelector { button.addTarget(targetSelector.target, action: targetSelector.action, for: .touchUpInside) } 39 | 40 | if image != nil && title != nil { 41 | button.contentEdgeInsets = UIEdgeInsets(top: 0, left: button.contentEdgeInsets.left + 4, bottom: 0, right: button.contentEdgeInsets.right + 8) 42 | button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: -4) 43 | } 44 | 45 | if style == .outline { 46 | button.layer.borderColor = contentColor?.cgColor 47 | button.layer.borderWidth = 2.0 48 | } 49 | 50 | return button 51 | } 52 | } 53 | 54 | extension UIView { 55 | static func make(backgroundColor: UIColor = .clear, 56 | alpha: CGFloat = 1.0, 57 | borderColor: UIColor = .clear, 58 | borderWidth: CGFloat = 0.0, 59 | height: CGFloat? = nil, 60 | width: CGFloat? = nil, 61 | cornerRadius: CGFloat = 0.0) -> UIView { 62 | let view = UIView() 63 | view.translatesAutoresizingMaskIntoConstraints = false 64 | view.backgroundColor = backgroundColor 65 | view.alpha = alpha 66 | view.layer.borderColor = borderColor.cgColor 67 | view.layer.borderWidth = borderWidth 68 | view.layer.cornerRadius = cornerRadius 69 | if let height = height { view.heightAnchor.constraint(equalToConstant: height).isActive = true } 70 | if let width = width { view.widthAnchor.constraint(equalToConstant: width).isActive = true } 71 | return view 72 | } 73 | } 74 | --------------------------------------------------------------------------------