├── .gitignore ├── CustomPresentation.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── CustomPresentation ├── Animator │ └── ViewPropertyAnimatorGroup.swift ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── FirstViewController.swift ├── Info.plist ├── Presentation │ ├── PresentationAnimationController.swift │ ├── PresentationController.swift │ ├── PresentationInteractionController.swift │ ├── PresentationKeyframe.swift │ ├── PresentationOperation.swift │ └── PresentationTransitioning.swift └── SecondViewController.swift ├── LICENSE ├── README.md └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /CustomPresentation.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4B4020E32138241C0094CCDC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4020E22138241C0094CCDC /* AppDelegate.swift */; }; 11 | 4B4020E52138241C0094CCDC /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4020E42138241C0094CCDC /* FirstViewController.swift */; }; 12 | 4B4020E82138241C0094CCDC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B4020E62138241C0094CCDC /* Main.storyboard */; }; 13 | 4B4020EA2138241D0094CCDC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B4020E92138241D0094CCDC /* Assets.xcassets */; }; 14 | 4B4020ED2138241D0094CCDC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B4020EB2138241D0094CCDC /* LaunchScreen.storyboard */; }; 15 | 4B4020F5213824BD0094CCDC /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4020F4213824BD0094CCDC /* SecondViewController.swift */; }; 16 | 4B4020F9213828780094CCDC /* PresentationTransitioning.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4020F8213828780094CCDC /* PresentationTransitioning.swift */; }; 17 | 4B4020FB213828E00094CCDC /* PresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4020FA213828E00094CCDC /* PresentationController.swift */; }; 18 | 4B4020FE213829550094CCDC /* PresentationAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4020FD213829550094CCDC /* PresentationAnimationController.swift */; }; 19 | 4B40210121382AAD0094CCDC /* ViewPropertyAnimatorGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B40210021382AAD0094CCDC /* ViewPropertyAnimatorGroup.swift */; }; 20 | 4B40210521382BF60094CCDC /* PresentationOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B40210421382BF60094CCDC /* PresentationOperation.swift */; }; 21 | 4B82F28D213A785600884F6E /* PresentationInteractionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B82F28C213A785600884F6E /* PresentationInteractionController.swift */; }; 22 | 4BDE0674213B3CC30085468D /* PresentationKeyframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDE0673213B3CC30085468D /* PresentationKeyframe.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 4B4020DF2138241C0094CCDC /* CustomPresentation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CustomPresentation.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 4B4020E22138241C0094CCDC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 28 | 4B4020E42138241C0094CCDC /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = ""; }; 29 | 4B4020E72138241C0094CCDC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 4B4020E92138241D0094CCDC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 31 | 4B4020EC2138241D0094CCDC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 32 | 4B4020EE2138241D0094CCDC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 4B4020F4213824BD0094CCDC /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; 34 | 4B4020F8213828780094CCDC /* PresentationTransitioning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationTransitioning.swift; sourceTree = ""; }; 35 | 4B4020FA213828E00094CCDC /* PresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationController.swift; sourceTree = ""; }; 36 | 4B4020FD213829550094CCDC /* PresentationAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationAnimationController.swift; sourceTree = ""; }; 37 | 4B40210021382AAD0094CCDC /* ViewPropertyAnimatorGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPropertyAnimatorGroup.swift; sourceTree = ""; }; 38 | 4B40210421382BF60094CCDC /* PresentationOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationOperation.swift; sourceTree = ""; }; 39 | 4B82F28C213A785600884F6E /* PresentationInteractionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationInteractionController.swift; sourceTree = ""; }; 40 | 4BDE0673213B3CC30085468D /* PresentationKeyframe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationKeyframe.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 4B4020DC2138241C0094CCDC /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 4B4020D62138241C0094CCDC = { 55 | isa = PBXGroup; 56 | children = ( 57 | 4B4020E12138241C0094CCDC /* CustomPresentation */, 58 | 4B4020E02138241C0094CCDC /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | 4B4020E02138241C0094CCDC /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 4B4020DF2138241C0094CCDC /* CustomPresentation.app */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | 4B4020E12138241C0094CCDC /* CustomPresentation */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 4B4020E22138241C0094CCDC /* AppDelegate.swift */, 74 | 4B4020E62138241C0094CCDC /* Main.storyboard */, 75 | 4B4020E42138241C0094CCDC /* FirstViewController.swift */, 76 | 4B4020F4213824BD0094CCDC /* SecondViewController.swift */, 77 | 4B4020FC213829010094CCDC /* Presentation */, 78 | 4B4020FF213829D40094CCDC /* Animator */, 79 | 4B4020E92138241D0094CCDC /* Assets.xcassets */, 80 | 4B4020EB2138241D0094CCDC /* LaunchScreen.storyboard */, 81 | 4B4020EE2138241D0094CCDC /* Info.plist */, 82 | ); 83 | path = CustomPresentation; 84 | sourceTree = ""; 85 | }; 86 | 4B4020FC213829010094CCDC /* Presentation */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 4B40210421382BF60094CCDC /* PresentationOperation.swift */, 90 | 4B4020F8213828780094CCDC /* PresentationTransitioning.swift */, 91 | 4B4020FA213828E00094CCDC /* PresentationController.swift */, 92 | 4B4020FD213829550094CCDC /* PresentationAnimationController.swift */, 93 | 4B82F28C213A785600884F6E /* PresentationInteractionController.swift */, 94 | 4BDE0673213B3CC30085468D /* PresentationKeyframe.swift */, 95 | ); 96 | path = Presentation; 97 | sourceTree = ""; 98 | }; 99 | 4B4020FF213829D40094CCDC /* Animator */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | 4B40210021382AAD0094CCDC /* ViewPropertyAnimatorGroup.swift */, 103 | ); 104 | path = Animator; 105 | sourceTree = ""; 106 | }; 107 | /* End PBXGroup section */ 108 | 109 | /* Begin PBXNativeTarget section */ 110 | 4B4020DE2138241C0094CCDC /* CustomPresentation */ = { 111 | isa = PBXNativeTarget; 112 | buildConfigurationList = 4B4020F12138241D0094CCDC /* Build configuration list for PBXNativeTarget "CustomPresentation" */; 113 | buildPhases = ( 114 | 4B4020DB2138241C0094CCDC /* Sources */, 115 | 4B4020DC2138241C0094CCDC /* Frameworks */, 116 | 4B4020DD2138241C0094CCDC /* Resources */, 117 | ); 118 | buildRules = ( 119 | ); 120 | dependencies = ( 121 | ); 122 | name = CustomPresentation; 123 | productName = CustomTransitions; 124 | productReference = 4B4020DF2138241C0094CCDC /* CustomPresentation.app */; 125 | productType = "com.apple.product-type.application"; 126 | }; 127 | /* End PBXNativeTarget section */ 128 | 129 | /* Begin PBXProject section */ 130 | 4B4020D72138241C0094CCDC /* Project object */ = { 131 | isa = PBXProject; 132 | attributes = { 133 | LastSwiftUpdateCheck = 0940; 134 | LastUpgradeCheck = 0940; 135 | ORGANIZATIONNAME = "Jiro Nagashima"; 136 | TargetAttributes = { 137 | 4B4020DE2138241C0094CCDC = { 138 | CreatedOnToolsVersion = 9.4; 139 | LastSwiftMigration = 1000; 140 | }; 141 | }; 142 | }; 143 | buildConfigurationList = 4B4020DA2138241C0094CCDC /* Build configuration list for PBXProject "CustomPresentation" */; 144 | compatibilityVersion = "Xcode 9.3"; 145 | developmentRegion = en; 146 | hasScannedForEncodings = 0; 147 | knownRegions = ( 148 | en, 149 | Base, 150 | ); 151 | mainGroup = 4B4020D62138241C0094CCDC; 152 | productRefGroup = 4B4020E02138241C0094CCDC /* Products */; 153 | projectDirPath = ""; 154 | projectRoot = ""; 155 | targets = ( 156 | 4B4020DE2138241C0094CCDC /* CustomPresentation */, 157 | ); 158 | }; 159 | /* End PBXProject section */ 160 | 161 | /* Begin PBXResourcesBuildPhase section */ 162 | 4B4020DD2138241C0094CCDC /* Resources */ = { 163 | isa = PBXResourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | 4B4020ED2138241D0094CCDC /* LaunchScreen.storyboard in Resources */, 167 | 4B4020EA2138241D0094CCDC /* Assets.xcassets in Resources */, 168 | 4B4020E82138241C0094CCDC /* Main.storyboard in Resources */, 169 | ); 170 | runOnlyForDeploymentPostprocessing = 0; 171 | }; 172 | /* End PBXResourcesBuildPhase section */ 173 | 174 | /* Begin PBXSourcesBuildPhase section */ 175 | 4B4020DB2138241C0094CCDC /* Sources */ = { 176 | isa = PBXSourcesBuildPhase; 177 | buildActionMask = 2147483647; 178 | files = ( 179 | 4B4020F5213824BD0094CCDC /* SecondViewController.swift in Sources */, 180 | 4BDE0674213B3CC30085468D /* PresentationKeyframe.swift in Sources */, 181 | 4B82F28D213A785600884F6E /* PresentationInteractionController.swift in Sources */, 182 | 4B4020FE213829550094CCDC /* PresentationAnimationController.swift in Sources */, 183 | 4B4020E52138241C0094CCDC /* FirstViewController.swift in Sources */, 184 | 4B40210521382BF60094CCDC /* PresentationOperation.swift in Sources */, 185 | 4B4020F9213828780094CCDC /* PresentationTransitioning.swift in Sources */, 186 | 4B40210121382AAD0094CCDC /* ViewPropertyAnimatorGroup.swift in Sources */, 187 | 4B4020E32138241C0094CCDC /* AppDelegate.swift in Sources */, 188 | 4B4020FB213828E00094CCDC /* PresentationController.swift in Sources */, 189 | ); 190 | runOnlyForDeploymentPostprocessing = 0; 191 | }; 192 | /* End PBXSourcesBuildPhase section */ 193 | 194 | /* Begin PBXVariantGroup section */ 195 | 4B4020E62138241C0094CCDC /* Main.storyboard */ = { 196 | isa = PBXVariantGroup; 197 | children = ( 198 | 4B4020E72138241C0094CCDC /* Base */, 199 | ); 200 | name = Main.storyboard; 201 | sourceTree = ""; 202 | }; 203 | 4B4020EB2138241D0094CCDC /* LaunchScreen.storyboard */ = { 204 | isa = PBXVariantGroup; 205 | children = ( 206 | 4B4020EC2138241D0094CCDC /* Base */, 207 | ); 208 | name = LaunchScreen.storyboard; 209 | sourceTree = ""; 210 | }; 211 | /* End PBXVariantGroup section */ 212 | 213 | /* Begin XCBuildConfiguration section */ 214 | 4B4020EF2138241D0094CCDC /* Debug */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | ALWAYS_SEARCH_USER_PATHS = NO; 218 | CLANG_ANALYZER_NONNULL = YES; 219 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 220 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 221 | CLANG_CXX_LIBRARY = "libc++"; 222 | CLANG_ENABLE_MODULES = YES; 223 | CLANG_ENABLE_OBJC_ARC = YES; 224 | CLANG_ENABLE_OBJC_WEAK = YES; 225 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 226 | CLANG_WARN_BOOL_CONVERSION = YES; 227 | CLANG_WARN_COMMA = YES; 228 | CLANG_WARN_CONSTANT_CONVERSION = YES; 229 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 231 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 237 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 238 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 239 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 240 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 241 | CLANG_WARN_STRICT_PROTOTYPES = YES; 242 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 243 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 244 | CLANG_WARN_UNREACHABLE_CODE = YES; 245 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 246 | CODE_SIGN_IDENTITY = "iPhone Developer"; 247 | COPY_PHASE_STRIP = NO; 248 | DEBUG_INFORMATION_FORMAT = dwarf; 249 | ENABLE_STRICT_OBJC_MSGSEND = YES; 250 | ENABLE_TESTABILITY = YES; 251 | GCC_C_LANGUAGE_STANDARD = gnu11; 252 | GCC_DYNAMIC_NO_PIC = NO; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_OPTIMIZATION_LEVEL = 0; 255 | GCC_PREPROCESSOR_DEFINITIONS = ( 256 | "DEBUG=1", 257 | "$(inherited)", 258 | ); 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 266 | MTL_ENABLE_DEBUG_INFO = YES; 267 | ONLY_ACTIVE_ARCH = YES; 268 | SDKROOT = iphoneos; 269 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 270 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 271 | }; 272 | name = Debug; 273 | }; 274 | 4B4020F02138241D0094CCDC /* Release */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ALWAYS_SEARCH_USER_PATHS = NO; 278 | CLANG_ANALYZER_NONNULL = YES; 279 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 280 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 281 | CLANG_CXX_LIBRARY = "libc++"; 282 | CLANG_ENABLE_MODULES = YES; 283 | CLANG_ENABLE_OBJC_ARC = YES; 284 | CLANG_ENABLE_OBJC_WEAK = YES; 285 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 286 | CLANG_WARN_BOOL_CONVERSION = YES; 287 | CLANG_WARN_COMMA = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 292 | CLANG_WARN_EMPTY_BODY = YES; 293 | CLANG_WARN_ENUM_CONVERSION = YES; 294 | CLANG_WARN_INFINITE_RECURSION = YES; 295 | CLANG_WARN_INT_CONVERSION = YES; 296 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 297 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 298 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 299 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 300 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 301 | CLANG_WARN_STRICT_PROTOTYPES = YES; 302 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 303 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 304 | CLANG_WARN_UNREACHABLE_CODE = YES; 305 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 306 | CODE_SIGN_IDENTITY = "iPhone Developer"; 307 | COPY_PHASE_STRIP = NO; 308 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 309 | ENABLE_NS_ASSERTIONS = NO; 310 | ENABLE_STRICT_OBJC_MSGSEND = YES; 311 | GCC_C_LANGUAGE_STANDARD = gnu11; 312 | GCC_NO_COMMON_BLOCKS = YES; 313 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 314 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 315 | GCC_WARN_UNDECLARED_SELECTOR = YES; 316 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 317 | GCC_WARN_UNUSED_FUNCTION = YES; 318 | GCC_WARN_UNUSED_VARIABLE = YES; 319 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 320 | MTL_ENABLE_DEBUG_INFO = NO; 321 | SDKROOT = iphoneos; 322 | SWIFT_COMPILATION_MODE = wholemodule; 323 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 324 | VALIDATE_PRODUCT = YES; 325 | }; 326 | name = Release; 327 | }; 328 | 4B4020F22138241D0094CCDC /* Debug */ = { 329 | isa = XCBuildConfiguration; 330 | buildSettings = { 331 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 332 | CODE_SIGN_STYLE = Automatic; 333 | INFOPLIST_FILE = CustomPresentation/Info.plist; 334 | LD_RUNPATH_SEARCH_PATHS = ( 335 | "$(inherited)", 336 | "@executable_path/Frameworks", 337 | ); 338 | PRODUCT_BUNDLE_IDENTIFIER = com.hedjirog.CustomPresentation; 339 | PRODUCT_NAME = "$(TARGET_NAME)"; 340 | SWIFT_VERSION = 4.2; 341 | TARGETED_DEVICE_FAMILY = "1,2"; 342 | }; 343 | name = Debug; 344 | }; 345 | 4B4020F32138241D0094CCDC /* Release */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 349 | CODE_SIGN_STYLE = Automatic; 350 | INFOPLIST_FILE = CustomPresentation/Info.plist; 351 | LD_RUNPATH_SEARCH_PATHS = ( 352 | "$(inherited)", 353 | "@executable_path/Frameworks", 354 | ); 355 | PRODUCT_BUNDLE_IDENTIFIER = com.hedjirog.CustomPresentation; 356 | PRODUCT_NAME = "$(TARGET_NAME)"; 357 | SWIFT_VERSION = 4.2; 358 | TARGETED_DEVICE_FAMILY = "1,2"; 359 | }; 360 | name = Release; 361 | }; 362 | /* End XCBuildConfiguration section */ 363 | 364 | /* Begin XCConfigurationList section */ 365 | 4B4020DA2138241C0094CCDC /* Build configuration list for PBXProject "CustomPresentation" */ = { 366 | isa = XCConfigurationList; 367 | buildConfigurations = ( 368 | 4B4020EF2138241D0094CCDC /* Debug */, 369 | 4B4020F02138241D0094CCDC /* Release */, 370 | ); 371 | defaultConfigurationIsVisible = 0; 372 | defaultConfigurationName = Release; 373 | }; 374 | 4B4020F12138241D0094CCDC /* Build configuration list for PBXNativeTarget "CustomPresentation" */ = { 375 | isa = XCConfigurationList; 376 | buildConfigurations = ( 377 | 4B4020F22138241D0094CCDC /* Debug */, 378 | 4B4020F32138241D0094CCDC /* Release */, 379 | ); 380 | defaultConfigurationIsVisible = 0; 381 | defaultConfigurationName = Release; 382 | }; 383 | /* End XCConfigurationList section */ 384 | }; 385 | rootObject = 4B4020D72138241C0094CCDC /* Project object */; 386 | } 387 | -------------------------------------------------------------------------------- /CustomPresentation.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CustomPresentation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CustomPresentation/Animator/ViewPropertyAnimatorGroup.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ViewPropertyAnimatorGroup: NSObject, UIViewImplicitlyAnimating { 4 | private let timingAnimator: UIViewPropertyAnimator 5 | private var animators: [UIViewPropertyAnimator] 6 | 7 | init(duration: TimeInterval, timingParameters: UITimingCurveProvider, animators: [UIViewPropertyAnimator]) { 8 | self.timingAnimator = UIViewPropertyAnimator(duration: duration, timingParameters: timingParameters) 9 | self.animators = [timingAnimator] + animators 10 | super.init() 11 | setupTimingAnimator() 12 | } 13 | 14 | private func setupTimingAnimator() { 15 | // Specifies a simple animation since UIViewPropertyAnimator completes immediately if animatable properties do not exist. 16 | let view = UIView() 17 | UIApplication.shared.keyWindow?.addSubview(view) 18 | timingAnimator.addAnimations { view.alpha = 0 } 19 | timingAnimator.addCompletion { _ in view.removeFromSuperview() } 20 | } 21 | 22 | func addCompletion(_ completion: @escaping (UIViewAnimatingPosition) -> Void) { 23 | timingAnimator.addCompletion(completion) 24 | } 25 | 26 | var state: UIViewAnimatingState { 27 | return timingAnimator.state 28 | } 29 | 30 | var isRunning: Bool { 31 | return timingAnimator.isRunning 32 | } 33 | 34 | var isReversed: Bool { 35 | get { 36 | return timingAnimator.isReversed 37 | } 38 | set(isReversed) { 39 | animators.forEach { $0.isReversed = isReversed } 40 | } 41 | } 42 | 43 | var fractionComplete: CGFloat { 44 | get { 45 | return timingAnimator.fractionComplete 46 | } 47 | set(fractionComplete) { 48 | animators.forEach { $0.fractionComplete = fractionComplete } 49 | } 50 | } 51 | 52 | func startAnimation() { 53 | animators.forEach { $0.startAnimation() } 54 | } 55 | 56 | func startAnimation(afterDelay delay: TimeInterval) { 57 | animators.forEach { $0.startAnimation(afterDelay: delay) } 58 | } 59 | 60 | func pauseAnimation() { 61 | animators.forEach { $0.pauseAnimation() } 62 | } 63 | 64 | func stopAnimation(_ withoutFinishing: Bool) { 65 | animators.forEach { $0.stopAnimation(withoutFinishing) } 66 | } 67 | 68 | func finishAnimation(at finalPosition: UIViewAnimatingPosition) { 69 | animators.forEach { $0.finishAnimation(at: finalPosition) } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /CustomPresentation/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | var window: UIWindow? 6 | 7 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 8 | return true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CustomPresentation/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 | } -------------------------------------------------------------------------------- /CustomPresentation/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CustomPresentation/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 | -------------------------------------------------------------------------------- /CustomPresentation/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 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 70 | 76 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /CustomPresentation/FirstViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class FirstViewController: UIViewController { 4 | @IBOutlet weak var controlView: UIView! 5 | @IBOutlet weak var outLabel: UILabel! 6 | 7 | private let tapGestureRecognizer = UITapGestureRecognizer() 8 | private let panGestureRecognizer = UIPanGestureRecognizer() 9 | 10 | override func viewDidLoad() { 11 | super.viewDidLoad() 12 | tapGestureRecognizer.addTarget(self, action: #selector(handleTap(_:))) 13 | panGestureRecognizer.addTarget(self, action: #selector(handlePan(_:))) 14 | controlView.addGestureRecognizer(tapGestureRecognizer) 15 | controlView.addGestureRecognizer(panGestureRecognizer) 16 | 17 | controlView.layer.shadowColor = UIColor.black.cgColor 18 | controlView.layer.shadowOpacity = 0.17 19 | controlView.layer.shadowRadius = 16 20 | } 21 | 22 | @objc private func handleTap(_ sender: UITapGestureRecognizer) { 23 | presentSecondViewController() 24 | } 25 | 26 | @objc private func handlePan(_ sender: UIPanGestureRecognizer) { 27 | if sender.state == .began { 28 | presentSecondViewController() 29 | } 30 | } 31 | 32 | private func presentSecondViewController() { 33 | let secondViewController = self.secondViewController 34 | let presentationController = PresentationController(presentedViewController: secondViewController, presentingViewController: self) 35 | secondViewController.transitioningDelegate = presentationController 36 | present(secondViewController, animated: true) 37 | } 38 | 39 | private var secondViewController: SecondViewController { 40 | return storyboard!.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController 41 | } 42 | } 43 | 44 | extension FirstViewController: PresentationAnimatedTransitioning { 45 | var transitionableViews: [TransitionableViewKey : UIView]? { 46 | return [.controlView: controlView, .outLabel: outLabel] 47 | } 48 | 49 | func prepareForTransition(using operation: PresentationOperation, targetViews: [TransitionableViewKey : UIView]?) { 50 | } 51 | 52 | func transitionAnimators(operation: PresentationOperation, duration: TimeInterval, targetViews: [TransitionableViewKey : UIView]?) -> [UIViewPropertyAnimator] { 53 | return [] 54 | } 55 | } 56 | 57 | extension FirstViewController: PresentationInteractiveTransitioning { 58 | var interactivePanGestureRecognizer: UIPanGestureRecognizer { 59 | return panGestureRecognizer 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /CustomPresentation/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UIRequiresFullScreen 32 | 33 | UIStatusBarHidden 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | UIViewControllerBasedStatusBarAppearance 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /CustomPresentation/Presentation/PresentationAnimationController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class PresentationAnimationController: NSObject, UIViewControllerAnimatedTransitioning { 4 | private let operation: PresentationOperation 5 | private var transitionAnimator: ViewPropertyAnimatorGroup? 6 | 7 | init(operation: PresentationOperation) { 8 | self.operation = operation 9 | } 10 | 11 | func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 12 | return operation.duration 13 | } 14 | 15 | func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 16 | interruptibleAnimator(using: transitionContext).startAnimation() 17 | } 18 | 19 | func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating { 20 | if let transitionAnimator = transitionAnimator { 21 | return transitionAnimator 22 | } 23 | 24 | prepareForTransitionIfNeeded(using: transitionContext) 25 | 26 | let duration = transitionDuration(using: transitionContext) 27 | let fromViewController = self.fromViewController(for: transitionContext) 28 | let toViewController = self.toViewController(for: transitionContext) 29 | let presentationController = self.presentationController(for: transitionContext) 30 | 31 | var animators: [UIViewPropertyAnimator] = [] 32 | [fromViewController, toViewController, presentationController].forEach { 33 | animators += $0.transitionAnimators(operation: operation, 34 | duration: transitionDuration(using: transitionContext), 35 | targetViews: toViewController.transitionableViews) 36 | } 37 | 38 | let timing = UISpringTimingParameters.init(dampingRatio: 1) 39 | let animator = ViewPropertyAnimatorGroup(duration: duration, timingParameters: timing, animators: animators) 40 | animator.addCompletion { position in 41 | let didComplete = position == .end 42 | transitionContext.completeTransition(didComplete) 43 | } 44 | transitionAnimator = animator 45 | return animator 46 | } 47 | 48 | private func prepareForTransitionIfNeeded(using transitionContext: UIViewControllerContextTransitioning) { 49 | let fromViewController = self.fromViewController(for: transitionContext) 50 | let toViewController = self.toViewController(for: transitionContext) 51 | let presentationController = self.presentationController(for: transitionContext) 52 | 53 | if operation == .present { 54 | toViewController.prepareForTransition(using: .dismiss, targetViews: fromViewController.transitionableViews) 55 | presentationController.prepareForTransition(using: .dismiss, targetViews: fromViewController.transitionableViews) 56 | } 57 | } 58 | 59 | private func prioritizedAnimators(from animators: [UIViewPropertyAnimator]) -> (primary: UIViewPropertyAnimator, secondary: [UIViewPropertyAnimator]) { 60 | var animators = ArraySlice(animators) 61 | let primary = animators.popFirst()! 62 | let secondary = Array(animators) 63 | return (primary, secondary) 64 | } 65 | 66 | func animationEnded(_ transitionCompleted: Bool) { 67 | transitionAnimator = nil 68 | } 69 | 70 | private func fromViewController(for transitionContext: UIViewControllerContextTransitioning) -> PresentationAnimatedTransitioning { 71 | return transitionContext.viewController(forKey: .from) as! PresentationAnimatedTransitioning 72 | } 73 | 74 | private func toViewController(for transitionContext: UIViewControllerContextTransitioning) -> PresentationAnimatedTransitioning { 75 | return transitionContext.viewController(forKey: .to) as! PresentationAnimatedTransitioning 76 | } 77 | 78 | private func presentationController(for transitionContext: UIViewControllerContextTransitioning) -> PresentationAnimatedTransitioning { 79 | let viewController = transitionContext.viewController(forKey: operation == .present ? .to : .from)! 80 | return viewController.presentationController as! PresentationAnimatedTransitioning 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /CustomPresentation/Presentation/PresentationController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class PresentationController: UIPresentationController { 4 | private let dimmingView = UIView() 5 | 6 | init(presentedViewController: PresentableViewController, presentingViewController: PresentableViewController) { 7 | super.init(presentedViewController: presentedViewController, presenting: presentingViewController) 8 | presentedViewController.modalPresentationStyle = .custom 9 | } 10 | 11 | override func presentationTransitionWillBegin() { 12 | let containerView = self.containerView! 13 | 14 | dimmingView.frame = containerView.bounds 15 | dimmingView.backgroundColor = .black 16 | containerView.addSubview(dimmingView) 17 | containerView.addSubview(presentedViewController.view) 18 | } 19 | } 20 | 21 | extension PresentationController: PresentationAnimatedTransitioning { 22 | var transitionableViews: [TransitionableViewKey : UIView]? { 23 | return nil 24 | } 25 | 26 | func prepareForTransition(using operation: PresentationOperation, targetViews: [TransitionableViewKey : UIView]?) { 27 | dimmingView.alpha = dimmingViewAlpha(for: operation) 28 | } 29 | 30 | func transitionAnimators(operation: PresentationOperation, duration: TimeInterval, targetViews: [TransitionableViewKey : UIView]?) -> [UIViewPropertyAnimator] { 31 | let dimmingAnimator = UIViewPropertyAnimator(duration: duration, curve: operation == .present ? .easeIn : .easeOut) { 32 | self.dimmingView.alpha = self.dimmingViewAlpha(for: operation) 33 | } 34 | return [dimmingAnimator] 35 | } 36 | 37 | private func dimmingViewAlpha(for operation: PresentationOperation) -> CGFloat { 38 | return operation == .present ? 0.2 : 0 39 | } 40 | } 41 | 42 | extension PresentationController: UIViewControllerTransitioningDelegate { 43 | func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { 44 | return self 45 | } 46 | 47 | func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 48 | return PresentationAnimationController(operation: .present) 49 | } 50 | 51 | func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 52 | return PresentationAnimationController(operation: .dismiss) 53 | } 54 | 55 | func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { 56 | let interactionController = PresentationInteractionController(operation: .present) 57 | let presentingViewController = self.presentingViewController as! PresentationInteractiveTransitioning 58 | interactionController.wantsInteractiveStart = presentingViewController.interactivePanGestureRecognizer.state == .began 59 | return interactionController 60 | } 61 | 62 | func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { 63 | let interactionController = PresentationInteractionController(operation: .dismiss) 64 | let presentedViewController = self.presentedViewController as! PresentationInteractiveTransitioning 65 | interactionController.wantsInteractiveStart = presentedViewController.interactivePanGestureRecognizer.state == .began 66 | return interactionController 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /CustomPresentation/Presentation/PresentationInteractionController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class PresentationInteractionController: UIPercentDrivenInteractiveTransition { 4 | private let operation: PresentationOperation 5 | private var interactiveAreaHeight: CGFloat? 6 | 7 | init(operation: PresentationOperation) { 8 | self.operation = operation 9 | super.init() 10 | } 11 | 12 | override func startInteractiveTransition(_ transitionContext: UIViewControllerContextTransitioning) { 13 | prepareForInteraction(using: transitionContext) 14 | super.startInteractiveTransition(transitionContext) 15 | } 16 | 17 | private func prepareForInteraction(using transitionContext: UIViewControllerContextTransitioning) { 18 | let fromViewController = self.fromViewController(for: transitionContext) 19 | let toViewController = self.toViewController(for: transitionContext) 20 | 21 | let fromInteractiveView = fromViewController.interactivePanGestureRecognizer.view! 22 | let toInteractiveView = toViewController.interactivePanGestureRecognizer.view! 23 | 24 | let fromTargetMinY = fromInteractiveView.frame.minY - fromInteractiveView.transform.ty 25 | let toTargetMinY = toInteractiveView.frame.minY - toInteractiveView.transform.ty 26 | 27 | interactiveAreaHeight = abs(fromTargetMinY - toTargetMinY) 28 | 29 | [fromViewController, toViewController].forEach { 30 | $0.interactivePanGestureRecognizer.addTarget(self, action: #selector(handlePan(_:))) 31 | } 32 | } 33 | 34 | @objc private func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) { 35 | switch gestureRecognizer.state { 36 | case .began: 37 | pause() 38 | case .changed: 39 | update(percentComplete(for: gestureRecognizer)) 40 | gestureRecognizer.setTranslation(.zero, in: nil) 41 | case .ended, .cancelled: 42 | if percentComplete > 0.5 { 43 | finish() 44 | } else { 45 | cancel() 46 | } 47 | default: 48 | break 49 | } 50 | } 51 | 52 | private func percentComplete(for gestureRecognizer: UIPanGestureRecognizer) -> CGFloat { 53 | return percentComplete + (operation == .present ? -1.0 : 1.0) * gestureRecognizer.translation(in: nil).y / interactiveAreaHeight! 54 | } 55 | 56 | private func fromViewController(for transitionContext: UIViewControllerContextTransitioning) -> PresentationInteractiveTransitioning { 57 | return transitionContext.viewController(forKey: .from) as! PresentationInteractiveTransitioning 58 | } 59 | 60 | private func toViewController(for transitionContext: UIViewControllerContextTransitioning) -> PresentationInteractiveTransitioning { 61 | return transitionContext.viewController(forKey: .to) as! PresentationInteractiveTransitioning 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /CustomPresentation/Presentation/PresentationKeyframe.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | protocol PresentationKeyframe { 4 | func startTime(for operation: PresentationOperation) -> Double 5 | var relativeDuration: Double { get } 6 | } 7 | 8 | extension PresentationKeyframe { 9 | static func makeKeyframes(_ animations: @escaping () -> Void) { 10 | UIView.animateKeyframes(withDuration: 0, delay: 0, animations: animations) 11 | } 12 | 13 | func add(for operation: PresentationOperation, animations: @escaping () -> Void) { 14 | UIView.addKeyframe(withRelativeStartTime: startTime(for: operation), 15 | relativeDuration: relativeDuration, 16 | animations: animations) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CustomPresentation/Presentation/PresentationOperation.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | enum PresentationOperation { 4 | case present 5 | case dismiss 6 | 7 | var duration: TimeInterval { return 0.6 } 8 | } 9 | -------------------------------------------------------------------------------- /CustomPresentation/Presentation/PresentationTransitioning.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | enum TransitionableViewKey { 4 | case controlView 5 | case inLabel 6 | case outLabel 7 | } 8 | 9 | protocol PresentationAnimatedTransitioning { 10 | var transitionableViews: [TransitionableViewKey : UIView]? { get } 11 | func prepareForTransition(using operation: PresentationOperation, targetViews: [TransitionableViewKey : UIView]?) 12 | func transitionAnimators(operation: PresentationOperation, duration: TimeInterval, targetViews: [TransitionableViewKey : UIView]?) -> [UIViewPropertyAnimator] 13 | } 14 | 15 | protocol PresentationInteractiveTransitioning { 16 | var interactivePanGestureRecognizer: UIPanGestureRecognizer { get } 17 | } 18 | 19 | typealias PresentableViewController = UIViewController & PresentationAnimatedTransitioning & PresentationInteractiveTransitioning 20 | -------------------------------------------------------------------------------- /CustomPresentation/SecondViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class SecondViewController: UIViewController { 4 | @IBOutlet weak var controlView: UIView! 5 | @IBOutlet weak var inLabel: UILabel! 6 | @IBOutlet weak var outLabel: UILabel! 7 | @IBOutlet weak var closeButton: UIButton! 8 | 9 | private let panGestureRecognizer = UIPanGestureRecognizer() 10 | 11 | override func viewDidLoad() { 12 | super.viewDidLoad() 13 | closeButton.addTarget(self, action: #selector(handleTap(_:)), for: .touchUpInside) 14 | panGestureRecognizer.addTarget(self, action: #selector(handlePan(_:))) 15 | controlView.addGestureRecognizer(panGestureRecognizer) 16 | 17 | controlView.layer.shadowColor = UIColor.black.cgColor 18 | controlView.layer.shadowOpacity = 0.17 19 | controlView.layer.shadowRadius = 16 20 | } 21 | 22 | override func viewWillDisappear(_ animated: Bool) { 23 | super.viewWillDisappear(animated) 24 | controlView.layer.shadowColor = UIColor.clear.cgColor 25 | } 26 | 27 | override func viewDidAppear(_ animated: Bool) { 28 | super.viewDidAppear(animated) 29 | controlView.layer.shadowColor = UIColor.black.cgColor 30 | } 31 | 32 | @objc private func handleTap(_ sender: UIButton) { 33 | dismiss(animated: true) 34 | } 35 | 36 | @objc private func handlePan(_ sender: UIPanGestureRecognizer) { 37 | if sender.state == .began { 38 | dismiss(animated: true) 39 | } 40 | } 41 | } 42 | 43 | extension SecondViewController: PresentationAnimatedTransitioning { 44 | var transitionableViews: [TransitionableViewKey : UIView]? { 45 | return [.controlView: controlView, .outLabel: outLabel, .inLabel: inLabel] 46 | } 47 | 48 | func prepareForTransition(using operation: PresentationOperation, targetViews: [TransitionableViewKey : UIView]?) { 49 | view.layoutIfNeeded() 50 | 51 | controlView.transform = controlViewTransform(for: operation, targetViews: targetViews) 52 | inLabel.transform = outLabelTransform(for: operation, targetViews: targetViews) 53 | outLabel.transform = inLabelTransform(for: operation, targetViews: targetViews) 54 | 55 | controlView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] 56 | controlView.layer.cornerRadius = controlViewCornerRadius(for: operation) 57 | 58 | inLabel.alpha = outLabelAlpha(for: operation) 59 | outLabel.alpha = inLabelAlpha(for: operation) 60 | 61 | closeButton.alpha = closeButtonAlpha(for: operation) 62 | } 63 | 64 | func transitionAnimators(operation: PresentationOperation, duration: TimeInterval, targetViews: [TransitionableViewKey : UIView]?) -> [UIViewPropertyAnimator] { 65 | let transformAnimator = UIViewPropertyAnimator(duration: duration, dampingRatio: 1) { 66 | self.controlView.transform = self.controlViewTransform(for: operation, targetViews: targetViews) 67 | self.inLabel.transform = self.outLabelTransform(for: operation, targetViews: targetViews) 68 | self.outLabel.transform = self.inLabelTransform(for: operation, targetViews: targetViews) 69 | } 70 | 71 | let cornerAnimator = UIViewPropertyAnimator(duration: duration, curve: .linear) { 72 | self.controlView.layer.cornerRadius = self.controlViewCornerRadius(for: operation) 73 | } 74 | 75 | let inLabelAnimator = UIViewPropertyAnimator(duration: duration, curve: operation == .present ? .easeIn : .easeOut) { 76 | self.inLabel.alpha = self.outLabelAlpha(for: operation) 77 | } 78 | let outLabelAnimator = UIViewPropertyAnimator(duration: duration, curve: operation == .present ? .easeOut : .easeIn) { 79 | self.outLabel.alpha = self.inLabelAlpha(for: operation) 80 | } 81 | inLabelAnimator.scrubsLinearly = false 82 | outLabelAnimator.scrubsLinearly = false 83 | 84 | let closeButtonAnimator = UIViewPropertyAnimator(duration: duration, curve: .linear) { 85 | Keyframe.makeKeyframes { 86 | Keyframe.closeButton.add(for: operation) { 87 | self.closeButton.alpha = self.closeButtonAlpha(for: operation) 88 | } 89 | } 90 | } 91 | 92 | return [transformAnimator, cornerAnimator, inLabelAnimator, outLabelAnimator, closeButtonAnimator] 93 | } 94 | 95 | private func controlViewTransform(for operation: PresentationOperation, targetViews: [TransitionableViewKey : UIView]?) -> CGAffineTransform { 96 | switch operation { 97 | case .present: 98 | return .identity 99 | case .dismiss: 100 | guard let targetView = targetViews?[.controlView] else { return .identity } 101 | return CGAffineTransform(translationX: 0, y: targetView.frame.minY - controlView.frame.minY) 102 | } 103 | } 104 | 105 | private func outLabelTransform(for operation: PresentationOperation, targetViews: [TransitionableViewKey : UIView]?) -> CGAffineTransform { 106 | switch operation { 107 | case .present: 108 | return .identity 109 | case .dismiss: 110 | guard let targetView = targetViews?[.outLabel] else { return .identity } 111 | let scale = CGAffineTransform(scaleX: targetView.frame.width / inLabel.frame.width, y: targetView.frame.height / inLabel.frame.height) 112 | let translation = CGAffineTransform(translationX: 0, y: targetView.frame.minY - inLabel.frame.minY + (targetView.frame.height - inLabel.frame.height) / 2) 113 | return scale.concatenating(translation) 114 | } 115 | } 116 | 117 | private func inLabelTransform(for operation: PresentationOperation, targetViews: [TransitionableViewKey : UIView]?) -> CGAffineTransform { 118 | switch operation { 119 | case .present: 120 | guard let targetView = targetViews?[.inLabel] else { return .identity } 121 | let scale = CGAffineTransform(scaleX: targetView.frame.width / outLabel.frame.width, y: targetView.frame.height / outLabel.frame.height) 122 | let translation = CGAffineTransform(translationX: 0, y: targetView.frame.minY - outLabel.frame.minY + (targetView.frame.height - outLabel.frame.height) / 2) 123 | return scale.concatenating(translation) 124 | case .dismiss: 125 | return .identity 126 | } 127 | } 128 | 129 | private func controlViewCornerRadius(for operation: PresentationOperation) -> CGFloat { 130 | return operation == .present ? 12 : 0 131 | } 132 | 133 | private func outLabelAlpha(for operation: PresentationOperation) -> CGFloat { 134 | return operation == .present ? 1 : 0 135 | } 136 | 137 | private func inLabelAlpha(for operation: PresentationOperation) -> CGFloat { 138 | return operation == .present ? 0 : 1 139 | } 140 | 141 | private func closeButtonAlpha(for operation: PresentationOperation) -> CGFloat { 142 | return operation == .present ? 1 : 0 143 | } 144 | 145 | private enum Keyframe: PresentationKeyframe { 146 | case closeButton 147 | 148 | func startTime(for operation: PresentationOperation) -> Double { 149 | switch self { 150 | case .closeButton: 151 | return operation == .present ? 1 - relativeDuration : 0 152 | } 153 | } 154 | 155 | var relativeDuration: Double { 156 | switch self { 157 | case .closeButton: 158 | return 0.5 159 | } 160 | } 161 | } 162 | } 163 | 164 | extension SecondViewController: PresentationInteractiveTransitioning { 165 | var interactivePanGestureRecognizer: UIPanGestureRecognizer { 166 | return panGestureRecognizer 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jiro Nagashima 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 | # CustomPresentation 2 | 3 | ![Swift](https://img.shields.io/badge/Swift-4.2-orange.svg?style=flat) 4 | ![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat) 5 | 6 | This application demonstrates a custom presentation that coordinates between multiple animations using [UIViewPropertyAnimator](https://developer.apple.com/documentation/uikit/uiviewpropertyanimator) and [view controller transition APIs](https://developer.apple.com/documentation/uikit/animation_and_haptics/view_controller_transitions). 7 | 8 | The idea of coordinating multiple animations was explained in the [_Advance Animation with UIKit_ WWDC 2017 session 230](https://developer.apple.com/videos/play/wwdc2017/230/). This application is implemented by referring to that approach. 9 | 10 | ## Demo 11 | 12 | ![demo](demo.gif) 13 | 14 | ## Overview 15 | 16 | ### Controllers 17 | 18 | #### [PresentationController](https://github.com/hedjirog/CustomPresentation/blob/master/CustomPresentation/Presentation/PresentationController.swift) 19 | 20 | 21 | - Manages the presentation style 22 | - Adds custom views for presentation 23 | - Inherits from `UIPresentationController` 24 | - Conforms to the `UIViewControllerTransitioningDelegate` protocol 25 | 26 | 27 | #### [PresentationAnimationController](https://github.com/hedjirog/CustomPresentation/blob/master/CustomPresentation/Presentation/PresentationAnimationController.swift) 28 | 29 | - Is responsible for creating the animations 30 | - Conforms to the `UIViewControllerAnimatedTransitioning` protocol 31 | 32 | #### [PresentationInteractionController](https://github.com/hedjirog/CustomPresentation/blob/master/CustomPresentation/Presentation/PresentationInteractionController.swift) 33 | 34 | - Drives the timing of custom animations using gesture recognizers 35 | - Inherits from `UIPercentDrivenInteractiveTransition` 36 | - Conforms to the `UIViewControllerInteractiveTransitioning` protocol 37 | 38 | ### Animations 39 | 40 | All transition animations are defined with `transitionAnimators` method of `PresentationAnimatedTransitioning` protocol. 41 | You can refer to the implementation of [SecondViewController](https://github.com/hedjirog/CustomPresentation/blob/master/CustomPresentation/SecondViewController.swift). 42 | 43 | ## Author 44 | 45 | Jiro [@hedjirog](https://twitter.com/hedjirog) 46 | 47 | ## License 48 | 49 | CustomPresentation is available under the MIT license. See the LICENSE file for more info. 50 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiro/CustomPresentation/2ed06ee9c00c3459a7f4867cb8574d5468db5f75/demo.gif --------------------------------------------------------------------------------