├── .gitignore ├── 1.png ├── 2.png ├── Example.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── Example ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── XPContentViewController.h ├── XPContentViewController.m ├── XPRootViewController.h ├── XPRootViewController.m └── main.m ├── LICENSE ├── README.md ├── SemiModal ├── UIViewController+XPSemiModal.h ├── UIViewController+XPSemiModal.m ├── XPSemiModalAnimatedTransitioning.h ├── XPSemiModalAnimatedTransitioning.m ├── XPSemiModalConfiguration.h ├── XPSemiModalConfiguration.m ├── XPSemiModalPresentationController.h ├── XPSemiModalPresentationController.m ├── XPSemiModalTransitioningDelegate.h └── XPSemiModalTransitioningDelegate.m └── preview.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 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopin/SemiModal/21f46cc2155d1b8ffd532765b74289813c4862ab/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopin/SemiModal/21f46cc2155d1b8ffd532765b74289813c4862ab/2.png -------------------------------------------------------------------------------- /Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 121E5E8B2008433800C8990F /* XPSemiModalConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 121E5E8A2008433800C8990F /* XPSemiModalConfiguration.m */; }; 11 | 1228ED922005EE0D00E1F7E7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228ED912005EE0D00E1F7E7 /* AppDelegate.m */; }; 12 | 1228ED982005EE0D00E1F7E7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1228ED962005EE0D00E1F7E7 /* Main.storyboard */; }; 13 | 1228ED9A2005EE0D00E1F7E7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1228ED992005EE0D00E1F7E7 /* Assets.xcassets */; }; 14 | 1228ED9D2005EE0D00E1F7E7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1228ED9B2005EE0D00E1F7E7 /* LaunchScreen.storyboard */; }; 15 | 1228EDA02005EE0D00E1F7E7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228ED9F2005EE0D00E1F7E7 /* main.m */; }; 16 | 1228EDAC2005F02600E1F7E7 /* UIViewController+XPSemiModal.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228EDAB2005F02600E1F7E7 /* UIViewController+XPSemiModal.m */; }; 17 | 1228EDAF2005F0BD00E1F7E7 /* XPContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228EDAE2005F0BD00E1F7E7 /* XPContentViewController.m */; }; 18 | 1228EDB22005F0D800E1F7E7 /* XPRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228EDB12005F0D800E1F7E7 /* XPRootViewController.m */; }; 19 | 1228EDB52005F25300E1F7E7 /* XPSemiModalTransitioningDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228EDB42005F25300E1F7E7 /* XPSemiModalTransitioningDelegate.m */; }; 20 | 1228EDB82005F26400E1F7E7 /* XPSemiModalAnimatedTransitioning.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228EDB72005F26400E1F7E7 /* XPSemiModalAnimatedTransitioning.m */; }; 21 | 1228EDBB2005F27E00E1F7E7 /* XPSemiModalPresentationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1228EDBA2005F27E00E1F7E7 /* XPSemiModalPresentationController.m */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 121E5E892008433800C8990F /* XPSemiModalConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPSemiModalConfiguration.h; sourceTree = ""; }; 26 | 121E5E8A2008433800C8990F /* XPSemiModalConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPSemiModalConfiguration.m; sourceTree = ""; }; 27 | 1228ED8D2005EE0D00E1F7E7 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 1228ED902005EE0D00E1F7E7 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 29 | 1228ED912005EE0D00E1F7E7 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 30 | 1228ED972005EE0D00E1F7E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 31 | 1228ED992005EE0D00E1F7E7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | 1228ED9C2005EE0D00E1F7E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 33 | 1228ED9E2005EE0D00E1F7E7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 1228ED9F2005EE0D00E1F7E7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | 1228EDAA2005F02600E1F7E7 /* UIViewController+XPSemiModal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+XPSemiModal.h"; sourceTree = ""; }; 36 | 1228EDAB2005F02600E1F7E7 /* UIViewController+XPSemiModal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+XPSemiModal.m"; sourceTree = ""; }; 37 | 1228EDAD2005F0BD00E1F7E7 /* XPContentViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPContentViewController.h; sourceTree = ""; }; 38 | 1228EDAE2005F0BD00E1F7E7 /* XPContentViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPContentViewController.m; sourceTree = ""; }; 39 | 1228EDB02005F0D800E1F7E7 /* XPRootViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRootViewController.h; sourceTree = ""; }; 40 | 1228EDB12005F0D800E1F7E7 /* XPRootViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPRootViewController.m; sourceTree = ""; }; 41 | 1228EDB32005F25300E1F7E7 /* XPSemiModalTransitioningDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPSemiModalTransitioningDelegate.h; sourceTree = ""; }; 42 | 1228EDB42005F25300E1F7E7 /* XPSemiModalTransitioningDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPSemiModalTransitioningDelegate.m; sourceTree = ""; }; 43 | 1228EDB62005F26400E1F7E7 /* XPSemiModalAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPSemiModalAnimatedTransitioning.h; sourceTree = ""; }; 44 | 1228EDB72005F26400E1F7E7 /* XPSemiModalAnimatedTransitioning.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPSemiModalAnimatedTransitioning.m; sourceTree = ""; }; 45 | 1228EDB92005F27E00E1F7E7 /* XPSemiModalPresentationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPSemiModalPresentationController.h; sourceTree = ""; }; 46 | 1228EDBA2005F27E00E1F7E7 /* XPSemiModalPresentationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPSemiModalPresentationController.m; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | 1228ED8A2005EE0D00E1F7E7 /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | ); 55 | runOnlyForDeploymentPostprocessing = 0; 56 | }; 57 | /* End PBXFrameworksBuildPhase section */ 58 | 59 | /* Begin PBXGroup section */ 60 | 1228ED842005EE0D00E1F7E7 = { 61 | isa = PBXGroup; 62 | children = ( 63 | 1228ED8F2005EE0D00E1F7E7 /* Example */, 64 | 1228ED8E2005EE0D00E1F7E7 /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 1228ED8E2005EE0D00E1F7E7 /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 1228ED8D2005EE0D00E1F7E7 /* Example.app */, 72 | ); 73 | name = Products; 74 | sourceTree = ""; 75 | }; 76 | 1228ED8F2005EE0D00E1F7E7 /* Example */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | 1228EDA62005EE4A00E1F7E7 /* SemiModal */, 80 | 1228ED902005EE0D00E1F7E7 /* AppDelegate.h */, 81 | 1228ED912005EE0D00E1F7E7 /* AppDelegate.m */, 82 | 1228EDB02005F0D800E1F7E7 /* XPRootViewController.h */, 83 | 1228EDB12005F0D800E1F7E7 /* XPRootViewController.m */, 84 | 1228EDAD2005F0BD00E1F7E7 /* XPContentViewController.h */, 85 | 1228EDAE2005F0BD00E1F7E7 /* XPContentViewController.m */, 86 | 1228ED962005EE0D00E1F7E7 /* Main.storyboard */, 87 | 1228ED992005EE0D00E1F7E7 /* Assets.xcassets */, 88 | 1228ED9B2005EE0D00E1F7E7 /* LaunchScreen.storyboard */, 89 | 1228ED9E2005EE0D00E1F7E7 /* Info.plist */, 90 | 1228ED9F2005EE0D00E1F7E7 /* main.m */, 91 | ); 92 | path = Example; 93 | sourceTree = ""; 94 | }; 95 | 1228EDA62005EE4A00E1F7E7 /* SemiModal */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 1228EDAA2005F02600E1F7E7 /* UIViewController+XPSemiModal.h */, 99 | 1228EDAB2005F02600E1F7E7 /* UIViewController+XPSemiModal.m */, 100 | 121E5E892008433800C8990F /* XPSemiModalConfiguration.h */, 101 | 121E5E8A2008433800C8990F /* XPSemiModalConfiguration.m */, 102 | 1228EDB62005F26400E1F7E7 /* XPSemiModalAnimatedTransitioning.h */, 103 | 1228EDB72005F26400E1F7E7 /* XPSemiModalAnimatedTransitioning.m */, 104 | 1228EDB92005F27E00E1F7E7 /* XPSemiModalPresentationController.h */, 105 | 1228EDBA2005F27E00E1F7E7 /* XPSemiModalPresentationController.m */, 106 | 1228EDB32005F25300E1F7E7 /* XPSemiModalTransitioningDelegate.h */, 107 | 1228EDB42005F25300E1F7E7 /* XPSemiModalTransitioningDelegate.m */, 108 | ); 109 | path = SemiModal; 110 | sourceTree = SOURCE_ROOT; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | 1228ED8C2005EE0D00E1F7E7 /* Example */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = 1228EDA32005EE0D00E1F7E7 /* Build configuration list for PBXNativeTarget "Example" */; 118 | buildPhases = ( 119 | 1228ED892005EE0D00E1F7E7 /* Sources */, 120 | 1228ED8A2005EE0D00E1F7E7 /* Frameworks */, 121 | 1228ED8B2005EE0D00E1F7E7 /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = Example; 128 | productName = Example; 129 | productReference = 1228ED8D2005EE0D00E1F7E7 /* Example.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | 1228ED852005EE0D00E1F7E7 /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | LastUpgradeCheck = 0910; 139 | ORGANIZATIONNAME = xiaopin; 140 | TargetAttributes = { 141 | 1228ED8C2005EE0D00E1F7E7 = { 142 | CreatedOnToolsVersion = 9.1; 143 | ProvisioningStyle = Automatic; 144 | }; 145 | }; 146 | }; 147 | buildConfigurationList = 1228ED882005EE0D00E1F7E7 /* Build configuration list for PBXProject "Example" */; 148 | compatibilityVersion = "Xcode 8.0"; 149 | developmentRegion = en; 150 | hasScannedForEncodings = 0; 151 | knownRegions = ( 152 | en, 153 | Base, 154 | ); 155 | mainGroup = 1228ED842005EE0D00E1F7E7; 156 | productRefGroup = 1228ED8E2005EE0D00E1F7E7 /* Products */; 157 | projectDirPath = ""; 158 | projectRoot = ""; 159 | targets = ( 160 | 1228ED8C2005EE0D00E1F7E7 /* Example */, 161 | ); 162 | }; 163 | /* End PBXProject section */ 164 | 165 | /* Begin PBXResourcesBuildPhase section */ 166 | 1228ED8B2005EE0D00E1F7E7 /* Resources */ = { 167 | isa = PBXResourcesBuildPhase; 168 | buildActionMask = 2147483647; 169 | files = ( 170 | 1228ED9D2005EE0D00E1F7E7 /* LaunchScreen.storyboard in Resources */, 171 | 1228ED9A2005EE0D00E1F7E7 /* Assets.xcassets in Resources */, 172 | 1228ED982005EE0D00E1F7E7 /* Main.storyboard in Resources */, 173 | ); 174 | runOnlyForDeploymentPostprocessing = 0; 175 | }; 176 | /* End PBXResourcesBuildPhase section */ 177 | 178 | /* Begin PBXSourcesBuildPhase section */ 179 | 1228ED892005EE0D00E1F7E7 /* Sources */ = { 180 | isa = PBXSourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | 1228EDAC2005F02600E1F7E7 /* UIViewController+XPSemiModal.m in Sources */, 184 | 1228EDBB2005F27E00E1F7E7 /* XPSemiModalPresentationController.m in Sources */, 185 | 1228EDA02005EE0D00E1F7E7 /* main.m in Sources */, 186 | 121E5E8B2008433800C8990F /* XPSemiModalConfiguration.m in Sources */, 187 | 1228EDB82005F26400E1F7E7 /* XPSemiModalAnimatedTransitioning.m in Sources */, 188 | 1228EDAF2005F0BD00E1F7E7 /* XPContentViewController.m in Sources */, 189 | 1228EDB22005F0D800E1F7E7 /* XPRootViewController.m in Sources */, 190 | 1228EDB52005F25300E1F7E7 /* XPSemiModalTransitioningDelegate.m in Sources */, 191 | 1228ED922005EE0D00E1F7E7 /* AppDelegate.m in Sources */, 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | /* End PBXSourcesBuildPhase section */ 196 | 197 | /* Begin PBXVariantGroup section */ 198 | 1228ED962005EE0D00E1F7E7 /* Main.storyboard */ = { 199 | isa = PBXVariantGroup; 200 | children = ( 201 | 1228ED972005EE0D00E1F7E7 /* Base */, 202 | ); 203 | name = Main.storyboard; 204 | sourceTree = ""; 205 | }; 206 | 1228ED9B2005EE0D00E1F7E7 /* LaunchScreen.storyboard */ = { 207 | isa = PBXVariantGroup; 208 | children = ( 209 | 1228ED9C2005EE0D00E1F7E7 /* Base */, 210 | ); 211 | name = LaunchScreen.storyboard; 212 | sourceTree = ""; 213 | }; 214 | /* End PBXVariantGroup section */ 215 | 216 | /* Begin XCBuildConfiguration section */ 217 | 1228EDA12005EE0D00E1F7E7 /* Debug */ = { 218 | isa = XCBuildConfiguration; 219 | buildSettings = { 220 | ALWAYS_SEARCH_USER_PATHS = NO; 221 | CLANG_ANALYZER_NONNULL = YES; 222 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 223 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 224 | CLANG_CXX_LIBRARY = "libc++"; 225 | CLANG_ENABLE_MODULES = YES; 226 | CLANG_ENABLE_OBJC_ARC = YES; 227 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_COMMA = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INFINITE_RECURSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = 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.1; 266 | MTL_ENABLE_DEBUG_INFO = YES; 267 | ONLY_ACTIVE_ARCH = YES; 268 | SDKROOT = iphoneos; 269 | }; 270 | name = Debug; 271 | }; 272 | 1228EDA22005EE0D00E1F7E7 /* Release */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ALWAYS_SEARCH_USER_PATHS = NO; 276 | CLANG_ANALYZER_NONNULL = YES; 277 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 278 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 279 | CLANG_CXX_LIBRARY = "libc++"; 280 | CLANG_ENABLE_MODULES = YES; 281 | CLANG_ENABLE_OBJC_ARC = YES; 282 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 283 | CLANG_WARN_BOOL_CONVERSION = YES; 284 | CLANG_WARN_COMMA = YES; 285 | CLANG_WARN_CONSTANT_CONVERSION = YES; 286 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 287 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 288 | CLANG_WARN_EMPTY_BODY = YES; 289 | CLANG_WARN_ENUM_CONVERSION = YES; 290 | CLANG_WARN_INFINITE_RECURSION = YES; 291 | CLANG_WARN_INT_CONVERSION = YES; 292 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 293 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 296 | CLANG_WARN_STRICT_PROTOTYPES = YES; 297 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 298 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 299 | CLANG_WARN_UNREACHABLE_CODE = YES; 300 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 301 | CODE_SIGN_IDENTITY = "iPhone Developer"; 302 | COPY_PHASE_STRIP = NO; 303 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 304 | ENABLE_NS_ASSERTIONS = NO; 305 | ENABLE_STRICT_OBJC_MSGSEND = YES; 306 | GCC_C_LANGUAGE_STANDARD = gnu11; 307 | GCC_NO_COMMON_BLOCKS = YES; 308 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 309 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 310 | GCC_WARN_UNDECLARED_SELECTOR = YES; 311 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 312 | GCC_WARN_UNUSED_FUNCTION = YES; 313 | GCC_WARN_UNUSED_VARIABLE = YES; 314 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 315 | MTL_ENABLE_DEBUG_INFO = NO; 316 | SDKROOT = iphoneos; 317 | VALIDATE_PRODUCT = YES; 318 | }; 319 | name = Release; 320 | }; 321 | 1228EDA42005EE0D00E1F7E7 /* Debug */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 325 | CODE_SIGN_STYLE = Automatic; 326 | INFOPLIST_FILE = Example/Info.plist; 327 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 328 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 329 | PRODUCT_BUNDLE_IDENTIFIER = com.0daybug.Example; 330 | PRODUCT_NAME = "$(TARGET_NAME)"; 331 | TARGETED_DEVICE_FAMILY = "1,2"; 332 | }; 333 | name = Debug; 334 | }; 335 | 1228EDA52005EE0D00E1F7E7 /* Release */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 339 | CODE_SIGN_STYLE = Automatic; 340 | INFOPLIST_FILE = Example/Info.plist; 341 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 342 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 343 | PRODUCT_BUNDLE_IDENTIFIER = com.0daybug.Example; 344 | PRODUCT_NAME = "$(TARGET_NAME)"; 345 | TARGETED_DEVICE_FAMILY = "1,2"; 346 | }; 347 | name = Release; 348 | }; 349 | /* End XCBuildConfiguration section */ 350 | 351 | /* Begin XCConfigurationList section */ 352 | 1228ED882005EE0D00E1F7E7 /* Build configuration list for PBXProject "Example" */ = { 353 | isa = XCConfigurationList; 354 | buildConfigurations = ( 355 | 1228EDA12005EE0D00E1F7E7 /* Debug */, 356 | 1228EDA22005EE0D00E1F7E7 /* Release */, 357 | ); 358 | defaultConfigurationIsVisible = 0; 359 | defaultConfigurationName = Release; 360 | }; 361 | 1228EDA32005EE0D00E1F7E7 /* Build configuration list for PBXNativeTarget "Example" */ = { 362 | isa = XCConfigurationList; 363 | buildConfigurations = ( 364 | 1228EDA42005EE0D00E1F7E7 /* Debug */, 365 | 1228EDA52005EE0D00E1F7E7 /* Release */, 366 | ); 367 | defaultConfigurationIsVisible = 0; 368 | defaultConfigurationName = Release; 369 | }; 370 | /* End XCConfigurationList section */ 371 | }; 372 | rootObject = 1228ED852005EE0D00E1F7E7 /* Project object */; 373 | } 374 | -------------------------------------------------------------------------------- /Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Example/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 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /Example/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 | -------------------------------------------------------------------------------- /Example/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 | 32 | 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 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /Example/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 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/XPContentViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XPContentViewController.h 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XPContentViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Example/XPContentViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // XPContentViewController.m 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "XPContentViewController.h" 10 | 11 | @interface XPContentViewController () 12 | 13 | @end 14 | 15 | @implementation XPContentViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | - (IBAction)buttonAction:(UIButton *)sender { 28 | [self dismissViewControllerAnimated:YES completion:nil]; 29 | } 30 | 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Example/XPRootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XPRootViewController.h 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XPRootViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Example/XPRootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // XPRootViewController.m 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "XPRootViewController.h" 10 | #import "XPContentViewController.h" 11 | #import "UIViewController+XPSemiModal.h" 12 | 13 | @interface XPRootViewController () 14 | 15 | @end 16 | 17 | @implementation XPRootViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view. 22 | } 23 | 24 | - (void)didReceiveMemoryWarning { 25 | [super didReceiveMemoryWarning]; 26 | // Dispose of any resources that can be recreated. 27 | } 28 | 29 | - (IBAction)buttonAction:(UIButton *)sender { 30 | NSString *identifier = NSStringFromClass([XPContentViewController class]); 31 | UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 32 | XPContentViewController *contentViewController = [storyboard instantiateViewControllerWithIdentifier:identifier]; 33 | XPSemiModalConfiguration *config = [XPSemiModalConfiguration defaultConfiguration]; 34 | [self presentSemiModalViewController:contentViewController contentHeight:300.0 configuration:config completion:nil]; 35 | 36 | 37 | // UIView *contentView = [[UIView alloc] init]; 38 | // contentView.backgroundColor = [UIColor purpleColor]; 39 | // XPSemiModalConfiguration *config = [XPSemiModalConfiguration defaultConfiguration]; 40 | // [self presentSemiModalView:contentView contentHeight:300.0 configuration:config completion:^{ 41 | // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 42 | // [self.presentedViewController dismissViewControllerAnimated:YES completion:nil]; 43 | // }); 44 | // }]; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Example/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 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 | # SemiModal 2 | 3 | [![Build](https://img.shields.io/wercker/ci/wercker/docs.svg)]() 4 | [![Platform](https://img.shields.io/badge/platform-iOS-blue.svg?style=flat)]() 5 | [![Language](https://img.shields.io/badge/platform-Objective%20C-blue.svg?style=flat)]() 6 | [![License](https://img.shields.io/badge/license-MIT-orange.svg?style=flat)]() 7 | 8 | # 该项目已废弃不再维护,请移步 [`iOS-Modal`](https://github.com/xiaopin/iOS-Modal.git) 9 | 10 | > 使用者只需关心`UIViewController+XPSemiModal.h`提供的使用方法以及`XPSemiModalConfiguration.h`所提供的定制功能即可,无需关心其他文件。如果对该功能实现有兴趣,你可自行查阅其他文件源代码。 11 | 12 | 类似淘宝添加购物车的模态视图动画 13 | 14 | 参考了[KNSemiModalViewController](https://github.com/kentnguyen/KNSemiModalViewController)的代码,但由于KNSemiModalViewController毕竟年代久远,当时还是用的addChildViewController的方式去实现的,所以现在采用iOS7提供的转场动画API以及iOS8推出的`UIPresentationController`来实现该功能。 15 | 16 | 提供Swift版本的实现,请查看[swift](https://github.com/xiaopin/SemiModal/tree/swift)分支。 17 | 18 | 19 | ## 环境要求 20 | 21 | - iOS8.0+ 22 | 23 | 24 | ## 用法 25 | 26 | - 将`SemiModal`文件夹拖入你的项目并导入`#import "UIViewController+XPSemiModal.h"`即可 27 | 28 | - 示例代码 29 | 30 | 1. 弹出控制器 31 | 32 | ```ObjC 33 | UIViewController *contentViewController = [[UIViewController alloc] init]; 34 | contentViewController.view.backgroundColor = [UIColor lightGrayColor]; 35 | XPSemiModalConfiguration *config = [XPSemiModalConfiguration defaultConfiguration]; 36 | [self presentSemiModalViewController:contentViewController contentHeight:300.0 configuration:config completion:nil]; 37 | ``` 38 | 39 | 2. 弹出自定义视图 40 | 41 | ```ObjC 42 | UIView *contentView = [[UIView alloc] init]; 43 | contentView.backgroundColor = [UIColor purpleColor]; 44 | XPSemiModalConfiguration *config = [XPSemiModalConfiguration defaultConfiguration]; 45 | [self presentSemiModalView:contentView contentHeight:300.0 configuration:config completion:^{ 46 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 47 | [self.presentedViewController dismissViewControllerAnimated:YES completion:nil]; 48 | }); 49 | }]; 50 | ``` 51 | 52 | ## 演示 53 | 54 | [![GIF](./preview.gif)]() 55 | 56 | [![1.png](./1.png)]() 57 | 58 | [![2.png](./2.png)]() 59 | 60 | ## 致谢 61 | 62 | 参考了[KNSemiModalViewController](https://github.com/kentnguyen/KNSemiModalViewController)的代码,感谢他们对开源社区做出的贡献。 63 | 64 | ## 协议 65 | 66 | `SemiModal`被许可在 MIT 协议下使用。查阅`LICENSE`文件来获得更多信息。 67 | -------------------------------------------------------------------------------- /SemiModal/UIViewController+XPSemiModal.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+XPSemiModal.h 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "XPSemiModalConfiguration.h" 11 | 12 | @interface UIViewController (XPSemiModal) 13 | 14 | 15 | /** 16 | 显示一个从底部弹起的半模态视图控制器 17 | 18 | @param contentViewController 模态视图控制器 19 | @param contentHeight 模态视图高度 20 | @param configuration 模态窗口配置信息 21 | @param completion 模态窗口显示完毕时的回调 22 | */ 23 | - (void)presentSemiModalViewController:(UIViewController *)contentViewController contentHeight:(CGFloat)contentHeight configuration:(XPSemiModalConfiguration *)configuration completion:(void (^)(void))completion NS_AVAILABLE_IOS(8_0); 24 | 25 | 26 | /** 27 | 显示一个从底部弹起的半模态视图 28 | 29 | 内部会创建一个UIViewController并将contentView添加到该控制器的view上,并添加`距离父视图上下左右均为0`的约束. 30 | 如果需要手动关闭模态窗口,则`谁弹出谁负责关闭`,即`[self.presentedViewController dismissViewControllerAnimated:YES completion:nil]` 31 | 32 | @param contentView 模态内容视图 33 | @param contentHeight 模态视图高度 34 | @param configuration 模态窗口配置信息 35 | @param completion 模态窗口显示完毕时的回调 36 | */ 37 | - (void)presentSemiModalView:(UIView *)contentView contentHeight:(CGFloat)contentHeight configuration:(XPSemiModalConfiguration *)configuration completion:(void (^)(void))completion NS_AVAILABLE_IOS(8_0); 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /SemiModal/UIViewController+XPSemiModal.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+XPSemiModal.m 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "UIViewController+XPSemiModal.h" 10 | #import "XPSemiModalPresentationController.h" 11 | #import "XPSemiModalTransitioningDelegate.h" 12 | #import 13 | 14 | @implementation UIViewController (XPSemiModal) 15 | 16 | - (void)presentSemiModalViewController:(UIViewController *)contentViewController contentHeight:(CGFloat)contentHeight configuration:(XPSemiModalConfiguration *)configuration completion:(void (^)(void))completion { 17 | NSAssert(configuration, @"The configuration argument cann't be nil."); 18 | if (self.presentedViewController) { return; } 19 | contentViewController.modalPresentationStyle = UIModalPresentationCustom; 20 | contentViewController.preferredContentSize = CGSizeMake(0.0, contentHeight); 21 | 22 | XPSemiModalTransitioningDelegate *transitioningDelegate = [[XPSemiModalTransitioningDelegate alloc] init]; 23 | contentViewController.transitioningDelegate = transitioningDelegate; 24 | // Keep strong references. 25 | static char delegateKey; 26 | objc_setAssociatedObject(contentViewController, &delegateKey, transitioningDelegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 27 | 28 | XPSemiModalPresentationController *presentationController = (XPSemiModalPresentationController *)contentViewController.presentationController; 29 | presentationController.configuration = configuration; 30 | 31 | if (configuration.enableShadow) { 32 | // Add shadow effect. 33 | contentViewController.view.layer.shadowColor = [[UIColor blackColor] CGColor]; 34 | contentViewController.view.layer.shadowOffset = CGSizeMake(0.0, -3.0); 35 | contentViewController.view.layer.shadowRadius = configuration.shadowRadius; 36 | contentViewController.view.layer.shadowOpacity = configuration.shadowOpacity; 37 | contentViewController.view.layer.shouldRasterize = YES; 38 | contentViewController.view.layer.rasterizationScale = [[UIScreen mainScreen] scale]; 39 | } 40 | 41 | [self presentViewController:contentViewController animated:YES completion:completion]; 42 | } 43 | 44 | 45 | - (void)presentSemiModalView:(UIView *)contentView contentHeight:(CGFloat)contentHeight configuration:(XPSemiModalConfiguration *)configuration completion:(void (^)(void))completion { 46 | NSAssert(contentView, @"The contentView cann't be nil."); 47 | UIViewController *contentViewController = [[UIViewController alloc] init]; 48 | contentViewController.view.backgroundColor = [UIColor clearColor]; 49 | [contentViewController.view addSubview:contentView]; 50 | contentView.translatesAutoresizingMaskIntoConstraints = NO; 51 | [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(contentView)]]; 52 | [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[contentView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(contentView)]]; 53 | 54 | [self presentSemiModalViewController:contentViewController contentHeight:contentHeight configuration:configuration completion:completion]; 55 | } 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalAnimatedTransitioning.h: -------------------------------------------------------------------------------- 1 | // 2 | // SemiModalAnimatedTransitioning.h 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XPSemiModalAnimatedTransitioning : NSObject 12 | 13 | @property (nonatomic, assign, getter=isPresentation) BOOL presentation; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalAnimatedTransitioning.m: -------------------------------------------------------------------------------- 1 | // 2 | // SemiModalAnimatedTransitioning.m 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "XPSemiModalAnimatedTransitioning.h" 10 | 11 | @implementation XPSemiModalAnimatedTransitioning 12 | 13 | - (NSTimeInterval)transitionDuration:(id)transitionContext { 14 | return 0.5; 15 | } 16 | 17 | - (void)animateTransition:(id)transitionContext { 18 | UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 19 | UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 20 | UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey]; 21 | UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey]; 22 | 23 | BOOL isPresentation = [self isPresentation]; 24 | 25 | if (isPresentation) { 26 | [transitionContext.containerView addSubview:toView]; 27 | } 28 | UIViewController *animatingVC = isPresentation ? toVC : fromVC; 29 | CGRect finalFrame = [transitionContext finalFrameForViewController:animatingVC]; 30 | animatingVC.view.frame = isPresentation ? CGRectOffset(finalFrame, 0.0, finalFrame.size.height) : finalFrame; 31 | 32 | [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState animations:^{ 33 | CGRect targetFrame = self.presentation ? finalFrame : CGRectOffset(finalFrame, 0.0, finalFrame.size.height); 34 | animatingVC.view.frame = targetFrame; 35 | } completion:^(BOOL finished) { 36 | if (!self.presentation) { 37 | [fromView removeFromSuperview]; 38 | } 39 | [transitionContext completeTransition:YES]; 40 | }]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // XPSemiModalConfiguration.h 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/12. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XPSemiModalConfiguration : NSObject 12 | 13 | /// 点击模态窗口之外的区域是否关闭模态窗口, 默认`YES` 14 | @property (nonatomic, assign, getter=isShouldDismissModal) BOOL shouldDismissModal; 15 | 16 | /// 是否使用阴影效果, 默认`YES` 17 | @property (nonatomic, assign, getter=isEnableShadow) BOOL enableShadow; 18 | /// 阴影透明度, 0.0~1.0, 默认`0.8` 19 | @property (nonatomic, assign) CGFloat shadowOpacity; 20 | /// 阴影圆角, 默认`5.0` 21 | @property (nonatomic, assign) CGFloat shadowRadius; 22 | 23 | /// 是否启用背景动画, 默认`YES` 24 | @property (nonatomic, assign, getter=isEnableBackgroundAnimation) BOOL enableBackgroundAnimation; 25 | /// 背景颜色(需要设置`enableBackgroundAnimation`为YES), 默认`blackColor` 26 | @property (nonatomic, strong) UIColor *backgroundColor; 27 | /// 背景图片(需要设置`enableBackgroundAnimation`为YES), 默认`nil` 28 | @property (nonatomic, strong) UIImage *backgroundImage; 29 | 30 | /// 背景透明度, 0.0~1.0, 默认`0.3` 31 | @property (nonatomic, assign) CGFloat backgroundOpacity; 32 | 33 | 34 | + (instancetype)defaultConfiguration; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // XPSemiModalConfiguration.m 3 | // Example 4 | // 5 | // Created by nhope on 2018/1/12. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "XPSemiModalConfiguration.h" 10 | 11 | @implementation XPSemiModalConfiguration 12 | 13 | + (instancetype)defaultConfiguration { 14 | return [[XPSemiModalConfiguration alloc] init]; 15 | } 16 | 17 | - (instancetype)init { 18 | if (self = [super init]) { 19 | _shouldDismissModal = YES; 20 | 21 | _enableShadow = YES; 22 | _shadowRadius = 5.0; 23 | _shadowOpacity = 0.8; 24 | 25 | _enableBackgroundAnimation = YES; 26 | _backgroundColor = [UIColor blackColor]; 27 | _backgroundOpacity = 0.3; 28 | } 29 | return self; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalPresentationController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XPSemiModalPresentationController.h 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class XPSemiModalConfiguration; 12 | 13 | @interface XPSemiModalPresentationController : UIPresentationController 14 | 15 | @property (nonatomic, strong) XPSemiModalConfiguration *configuration; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalPresentationController.m: -------------------------------------------------------------------------------- 1 | // 2 | // XPSemiModalPresentationController.m 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "XPSemiModalPresentationController.h" 10 | #import "XPSemiModalConfiguration.h" 11 | 12 | @interface XPSemiModalPresentationController () 13 | 14 | @property (nonatomic, strong) UIImageView *backgroundView; 15 | @property (nonatomic, strong) UIView *animatingView; 16 | @property (nonatomic, strong) UIView *dimmingView; 17 | 18 | @end 19 | 20 | @implementation XPSemiModalPresentationController 21 | 22 | - (instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController presentingViewController:(UIViewController *)presentingViewController { 23 | self = [super initWithPresentedViewController:presentedViewController presentingViewController:presentingViewController]; 24 | if (self) { 25 | _configuration = [XPSemiModalConfiguration defaultConfiguration]; 26 | _backgroundView = [[UIImageView alloc] init]; 27 | _backgroundView.backgroundColor = _configuration.backgroundColor; 28 | _dimmingView = [[UIView alloc] init]; 29 | _dimmingView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:_configuration.backgroundOpacity]; 30 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizerAction:)]; 31 | [_dimmingView addGestureRecognizer:tap]; 32 | } 33 | return self; 34 | } 35 | 36 | - (CGRect)frameOfPresentedViewInContainerView { 37 | CGSize containerSize = self.containerView.bounds.size; 38 | CGFloat width = containerSize.width; 39 | CGFloat height = MIN(containerSize.height, self.presentedViewController.preferredContentSize.height); 40 | CGRect presentedViewFrame = CGRectMake(0.0, containerSize.height-height, width, height); 41 | return presentedViewFrame; 42 | } 43 | 44 | - (void)containerViewWillLayoutSubviews { 45 | [super containerViewWillLayoutSubviews]; 46 | _backgroundView.frame = self.containerView.bounds; 47 | _dimmingView.frame = self.containerView.bounds; 48 | self.presentedView.frame = [self frameOfPresentedViewInContainerView]; 49 | } 50 | 51 | - (void)presentationTransitionWillBegin { 52 | [super presentationTransitionWillBegin]; 53 | 54 | if (_configuration.enableBackgroundAnimation) { 55 | UIWindow *window = [[UIApplication sharedApplication] keyWindow]; 56 | UIView *snapshotView = [window snapshotViewAfterScreenUpdates:YES]; 57 | NSAssert(window, @"UIApplication.sharedApplication.keyWindow is nil"); 58 | if (snapshotView) { 59 | _animatingView = snapshotView; 60 | [_backgroundView addSubview:snapshotView]; 61 | snapshotView.translatesAutoresizingMaskIntoConstraints = NO; 62 | [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[snapshotView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(snapshotView)]]; 63 | [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[snapshotView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(snapshotView)]]; 64 | } 65 | [self.containerView addSubview:_backgroundView]; 66 | } 67 | 68 | [self.containerView addSubview:_dimmingView]; 69 | _dimmingView.alpha = 0.0; 70 | 71 | [self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id _Nonnull context) { 72 | self.dimmingView.alpha = 1.0; 73 | if (self.configuration.enableBackgroundAnimation) { 74 | CAAnimationGroup *animation = [self backgroundTranslateAnimationWithForward:YES]; 75 | [self.animatingView.layer addAnimation:animation forKey:nil]; 76 | } 77 | } completion:nil]; 78 | } 79 | 80 | - (void)dismissalTransitionWillBegin { 81 | [super dismissalTransitionWillBegin]; 82 | [self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id _Nonnull context) { 83 | self.dimmingView.alpha = 0.0; 84 | if (self.configuration.enableBackgroundAnimation) { 85 | CAAnimationGroup *animation = [self backgroundTranslateAnimationWithForward:NO]; 86 | [self.animatingView.layer addAnimation:animation forKey:nil]; 87 | } 88 | } completion:nil]; 89 | } 90 | 91 | - (void)tapGestureRecognizerAction:(UITapGestureRecognizer *)sender { 92 | if (_configuration.shouldDismissModal) { 93 | [self.presentedViewController dismissViewControllerAnimated:YES completion:nil]; 94 | } 95 | } 96 | 97 | - (CAAnimationGroup *)backgroundTranslateAnimationWithForward:(BOOL)forward { 98 | BOOL iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); 99 | CGFloat translateFactor = iPad ? -0.08 : -0.04; 100 | CGFloat rotateFactor = iPad ? 7.5 : 15.0; 101 | CGFloat scale = 0.8; 102 | CFTimeInterval animationDuration = 0.5; 103 | 104 | CATransform3D t1 = CATransform3DIdentity; 105 | t1.m34 = -1.0/900.0; 106 | t1 = CATransform3DScale(t1, 0.95, 0.95, 1.0); 107 | t1 = CATransform3DRotate(t1, rotateFactor*M_PI/180.0, 1.0, 0.0, 0.0); 108 | 109 | CATransform3D t2 = CATransform3DIdentity; 110 | t2.m34 = t1.m34; 111 | t2 = CATransform3DTranslate(t2, 0.0, self.presentedViewController.view.frame.size.height*translateFactor, 0.0); 112 | t2 = CATransform3DScale(t2, scale, scale, 1.0); 113 | 114 | CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform"]; 115 | animation1.toValue = [NSValue valueWithCATransform3D:t1]; 116 | animation1.duration = animationDuration / 2; 117 | animation1.fillMode = kCAFillModeForwards; 118 | animation1.removedOnCompletion = NO; 119 | animation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 120 | 121 | CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform"]; 122 | animation2.toValue = [NSValue valueWithCATransform3D:(forward ? t2 : CATransform3DIdentity)]; 123 | animation2.beginTime = animation1.duration; 124 | animation2.duration = animation1.duration; 125 | animation2.fillMode = kCAFillModeForwards; 126 | animation2.removedOnCompletion = NO; 127 | 128 | CAAnimationGroup *group = [CAAnimationGroup animation]; 129 | group.fillMode = kCAFillModeForwards; 130 | group.removedOnCompletion = NO; 131 | group.duration = animationDuration; 132 | group.animations = @[animation1, animation2]; 133 | return group; 134 | } 135 | 136 | - (void)setConfiguration:(XPSemiModalConfiguration *)configuration { 137 | NSAssert(configuration, @"The configuration can't be nil."); 138 | _configuration = configuration; 139 | _backgroundView.backgroundColor = configuration.backgroundColor; 140 | _backgroundView.image = configuration.backgroundImage; 141 | _dimmingView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:configuration.backgroundOpacity]; 142 | } 143 | 144 | @end 145 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalTransitioningDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // XPSemiModalTransitioningDelegate.h 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XPSemiModalTransitioningDelegate : NSObject 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SemiModal/XPSemiModalTransitioningDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // XPSemiModalTransitioningDelegate.m 3 | // https://github.com/xiaopin/SemiModal.git 4 | // 5 | // Created by nhope on 2018/1/10. 6 | // Copyright © 2018年 xiaopin. All rights reserved. 7 | // 8 | 9 | #import "XPSemiModalTransitioningDelegate.h" 10 | #import "XPSemiModalAnimatedTransitioning.h" 11 | #import "XPSemiModalPresentationController.h" 12 | 13 | @implementation XPSemiModalTransitioningDelegate 14 | 15 | - (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source { 16 | return [[XPSemiModalPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting]; 17 | } 18 | 19 | - (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { 20 | XPSemiModalAnimatedTransitioning *animated = [[XPSemiModalAnimatedTransitioning alloc] init]; 21 | animated.presentation = YES; 22 | return animated; 23 | } 24 | 25 | - (id)animationControllerForDismissedController:(UIViewController *)dismissed { 26 | XPSemiModalAnimatedTransitioning *animated = [[XPSemiModalAnimatedTransitioning alloc] init]; 27 | animated.presentation = NO; 28 | return animated; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopin/SemiModal/21f46cc2155d1b8ffd532765b74289813c4862ab/preview.gif --------------------------------------------------------------------------------