├── .gitignore ├── Assets ├── Click.gif ├── Detents.gif ├── Header.png ├── Overlay.gif ├── SelfSizing.gif └── SplitSheet.mp4 ├── Example ├── SplitSheetExample.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── aheze.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── SplitSheetExample │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── Image.imageset │ │ ├── Contents.json │ │ └── harold-wainwright-aEK8X33l7V4-unsplash (1).jpg │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── SceneDelegate.swift │ └── ViewController.swift ├── LICENSE ├── Package.swift ├── README.md └── Sources └── SplitSheet.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | .swiftpm/ -------------------------------------------------------------------------------- /Assets/Click.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aheze/SplitSheet/aaff7d39086758aca11ac4bd2b54b539190a42bd/Assets/Click.gif -------------------------------------------------------------------------------- /Assets/Detents.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aheze/SplitSheet/aaff7d39086758aca11ac4bd2b54b539190a42bd/Assets/Detents.gif -------------------------------------------------------------------------------- /Assets/Header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aheze/SplitSheet/aaff7d39086758aca11ac4bd2b54b539190a42bd/Assets/Header.png -------------------------------------------------------------------------------- /Assets/Overlay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aheze/SplitSheet/aaff7d39086758aca11ac4bd2b54b539190a42bd/Assets/Overlay.gif -------------------------------------------------------------------------------- /Assets/SelfSizing.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aheze/SplitSheet/aaff7d39086758aca11ac4bd2b54b539190a42bd/Assets/SelfSizing.gif -------------------------------------------------------------------------------- /Assets/SplitSheet.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aheze/SplitSheet/aaff7d39086758aca11ac4bd2b54b539190a42bd/Assets/SplitSheet.mp4 -------------------------------------------------------------------------------- /Example/SplitSheetExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3CB3F260284D207200BC03E4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB3F25F284D207200BC03E4 /* AppDelegate.swift */; }; 11 | 3CB3F262284D207200BC03E4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB3F261284D207200BC03E4 /* SceneDelegate.swift */; }; 12 | 3CB3F264284D207200BC03E4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB3F263284D207200BC03E4 /* ViewController.swift */; }; 13 | 3CB3F267284D207200BC03E4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3CB3F265284D207200BC03E4 /* Main.storyboard */; }; 14 | 3CB3F269284D207400BC03E4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3CB3F268284D207400BC03E4 /* Assets.xcassets */; }; 15 | 3CB3F26C284D207400BC03E4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3CB3F26A284D207400BC03E4 /* LaunchScreen.storyboard */; }; 16 | 3CB3F276284D210500BC03E4 /* SplitSheet in Frameworks */ = {isa = PBXBuildFile; productRef = 3CB3F275284D210500BC03E4 /* SplitSheet */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 3CB3F25C284D207200BC03E4 /* SplitSheetExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SplitSheetExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 3CB3F25F284D207200BC03E4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 3CB3F261284D207200BC03E4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 23 | 3CB3F263284D207200BC03E4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 3CB3F266284D207200BC03E4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 3CB3F268284D207400BC03E4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 3CB3F26B284D207400BC03E4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 3CB3F26D284D207400BC03E4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 3CB3F273284D208100BC03E4 /* SplitSheet */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SplitSheet; path = ../..; sourceTree = ""; }; 29 | 3CB3F277284D8E1A00BC03E4 /* SplitSheet */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SplitSheet; path = ..; sourceTree = ""; }; 30 | /* End PBXFileReference section */ 31 | 32 | /* Begin PBXFrameworksBuildPhase section */ 33 | 3CB3F259284D207200BC03E4 /* Frameworks */ = { 34 | isa = PBXFrameworksBuildPhase; 35 | buildActionMask = 2147483647; 36 | files = ( 37 | 3CB3F276284D210500BC03E4 /* SplitSheet in Frameworks */, 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 3CB3F253284D207200BC03E4 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 3CB3F273284D208100BC03E4 /* SplitSheet */, 48 | 3CB3F277284D8E1A00BC03E4 /* SplitSheet */, 49 | 3CB3F25E284D207200BC03E4 /* SplitSheetExample */, 50 | 3CB3F25D284D207200BC03E4 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | 3CB3F25D284D207200BC03E4 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 3CB3F25C284D207200BC03E4 /* SplitSheetExample.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | 3CB3F25E284D207200BC03E4 /* SplitSheetExample */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 3CB3F25F284D207200BC03E4 /* AppDelegate.swift */, 66 | 3CB3F261284D207200BC03E4 /* SceneDelegate.swift */, 67 | 3CB3F263284D207200BC03E4 /* ViewController.swift */, 68 | 3CB3F265284D207200BC03E4 /* Main.storyboard */, 69 | 3CB3F268284D207400BC03E4 /* Assets.xcassets */, 70 | 3CB3F26A284D207400BC03E4 /* LaunchScreen.storyboard */, 71 | 3CB3F26D284D207400BC03E4 /* Info.plist */, 72 | ); 73 | path = SplitSheetExample; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | 3CB3F25B284D207200BC03E4 /* SplitSheetExample */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = 3CB3F270284D207400BC03E4 /* Build configuration list for PBXNativeTarget "SplitSheetExample" */; 82 | buildPhases = ( 83 | 3CB3F258284D207200BC03E4 /* Sources */, 84 | 3CB3F259284D207200BC03E4 /* Frameworks */, 85 | 3CB3F25A284D207200BC03E4 /* Resources */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = SplitSheetExample; 92 | packageProductDependencies = ( 93 | 3CB3F275284D210500BC03E4 /* SplitSheet */, 94 | ); 95 | productName = SplitSheetExample; 96 | productReference = 3CB3F25C284D207200BC03E4 /* SplitSheetExample.app */; 97 | productType = "com.apple.product-type.application"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | 3CB3F254284D207200BC03E4 /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | BuildIndependentTargetsInParallel = 1; 106 | LastSwiftUpdateCheck = 1330; 107 | LastUpgradeCheck = 1330; 108 | TargetAttributes = { 109 | 3CB3F25B284D207200BC03E4 = { 110 | CreatedOnToolsVersion = 13.3; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = 3CB3F257284D207200BC03E4 /* Build configuration list for PBXProject "SplitSheetExample" */; 115 | compatibilityVersion = "Xcode 13.0"; 116 | developmentRegion = en; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = 3CB3F253284D207200BC03E4; 123 | packageReferences = ( 124 | 3CB3F274284D210500BC03E4 /* XCRemoteSwiftPackageReference "SplitSheet" */, 125 | ); 126 | productRefGroup = 3CB3F25D284D207200BC03E4 /* Products */; 127 | projectDirPath = ""; 128 | projectRoot = ""; 129 | targets = ( 130 | 3CB3F25B284D207200BC03E4 /* SplitSheetExample */, 131 | ); 132 | }; 133 | /* End PBXProject section */ 134 | 135 | /* Begin PBXResourcesBuildPhase section */ 136 | 3CB3F25A284D207200BC03E4 /* Resources */ = { 137 | isa = PBXResourcesBuildPhase; 138 | buildActionMask = 2147483647; 139 | files = ( 140 | 3CB3F26C284D207400BC03E4 /* LaunchScreen.storyboard in Resources */, 141 | 3CB3F269284D207400BC03E4 /* Assets.xcassets in Resources */, 142 | 3CB3F267284D207200BC03E4 /* Main.storyboard in Resources */, 143 | ); 144 | runOnlyForDeploymentPostprocessing = 0; 145 | }; 146 | /* End PBXResourcesBuildPhase section */ 147 | 148 | /* Begin PBXSourcesBuildPhase section */ 149 | 3CB3F258284D207200BC03E4 /* Sources */ = { 150 | isa = PBXSourcesBuildPhase; 151 | buildActionMask = 2147483647; 152 | files = ( 153 | 3CB3F264284D207200BC03E4 /* ViewController.swift in Sources */, 154 | 3CB3F260284D207200BC03E4 /* AppDelegate.swift in Sources */, 155 | 3CB3F262284D207200BC03E4 /* SceneDelegate.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | 3CB3F265284D207200BC03E4 /* Main.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 3CB3F266284D207200BC03E4 /* Base */, 166 | ); 167 | name = Main.storyboard; 168 | sourceTree = ""; 169 | }; 170 | 3CB3F26A284D207400BC03E4 /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | 3CB3F26B284D207400BC03E4 /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | 3CB3F26E284D207400BC03E4 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ALWAYS_SEARCH_USER_PATHS = NO; 185 | CLANG_ANALYZER_NONNULL = YES; 186 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 187 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 188 | CLANG_ENABLE_MODULES = YES; 189 | CLANG_ENABLE_OBJC_ARC = YES; 190 | CLANG_ENABLE_OBJC_WEAK = YES; 191 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 192 | CLANG_WARN_BOOL_CONVERSION = YES; 193 | CLANG_WARN_COMMA = YES; 194 | CLANG_WARN_CONSTANT_CONVERSION = YES; 195 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 196 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 197 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 198 | CLANG_WARN_EMPTY_BODY = YES; 199 | CLANG_WARN_ENUM_CONVERSION = YES; 200 | CLANG_WARN_INFINITE_RECURSION = YES; 201 | CLANG_WARN_INT_CONVERSION = YES; 202 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 203 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 204 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 205 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 206 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 207 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 208 | CLANG_WARN_STRICT_PROTOTYPES = YES; 209 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 210 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 211 | CLANG_WARN_UNREACHABLE_CODE = YES; 212 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 213 | COPY_PHASE_STRIP = NO; 214 | DEBUG_INFORMATION_FORMAT = dwarf; 215 | ENABLE_STRICT_OBJC_MSGSEND = YES; 216 | ENABLE_TESTABILITY = YES; 217 | GCC_C_LANGUAGE_STANDARD = gnu11; 218 | GCC_DYNAMIC_NO_PIC = NO; 219 | GCC_NO_COMMON_BLOCKS = YES; 220 | GCC_OPTIMIZATION_LEVEL = 0; 221 | GCC_PREPROCESSOR_DEFINITIONS = ( 222 | "DEBUG=1", 223 | "$(inherited)", 224 | ); 225 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 226 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 227 | GCC_WARN_UNDECLARED_SELECTOR = YES; 228 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 229 | GCC_WARN_UNUSED_FUNCTION = YES; 230 | GCC_WARN_UNUSED_VARIABLE = YES; 231 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 232 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 233 | MTL_FAST_MATH = YES; 234 | ONLY_ACTIVE_ARCH = YES; 235 | SDKROOT = iphoneos; 236 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 237 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 238 | }; 239 | name = Debug; 240 | }; 241 | 3CB3F26F284D207400BC03E4 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | ALWAYS_SEARCH_USER_PATHS = NO; 245 | CLANG_ANALYZER_NONNULL = YES; 246 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 247 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 248 | CLANG_ENABLE_MODULES = YES; 249 | CLANG_ENABLE_OBJC_ARC = YES; 250 | CLANG_ENABLE_OBJC_WEAK = YES; 251 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 252 | CLANG_WARN_BOOL_CONVERSION = YES; 253 | CLANG_WARN_COMMA = YES; 254 | CLANG_WARN_CONSTANT_CONVERSION = YES; 255 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 256 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 257 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 258 | CLANG_WARN_EMPTY_BODY = YES; 259 | CLANG_WARN_ENUM_CONVERSION = YES; 260 | CLANG_WARN_INFINITE_RECURSION = YES; 261 | CLANG_WARN_INT_CONVERSION = YES; 262 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 263 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 264 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 265 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 266 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 267 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 268 | CLANG_WARN_STRICT_PROTOTYPES = YES; 269 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 270 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 271 | CLANG_WARN_UNREACHABLE_CODE = YES; 272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 273 | COPY_PHASE_STRIP = NO; 274 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 275 | ENABLE_NS_ASSERTIONS = NO; 276 | ENABLE_STRICT_OBJC_MSGSEND = YES; 277 | GCC_C_LANGUAGE_STANDARD = gnu11; 278 | GCC_NO_COMMON_BLOCKS = YES; 279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 281 | GCC_WARN_UNDECLARED_SELECTOR = YES; 282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 283 | GCC_WARN_UNUSED_FUNCTION = YES; 284 | GCC_WARN_UNUSED_VARIABLE = YES; 285 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 286 | MTL_ENABLE_DEBUG_INFO = NO; 287 | MTL_FAST_MATH = YES; 288 | SDKROOT = iphoneos; 289 | SWIFT_COMPILATION_MODE = wholemodule; 290 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 291 | VALIDATE_PRODUCT = YES; 292 | }; 293 | name = Release; 294 | }; 295 | 3CB3F271284D207400BC03E4 /* Debug */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 299 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 300 | CODE_SIGN_STYLE = Automatic; 301 | CURRENT_PROJECT_VERSION = 1; 302 | DEVELOPMENT_TEAM = YA533DMD5J; 303 | GENERATE_INFOPLIST_FILE = YES; 304 | INFOPLIST_FILE = SplitSheetExample/Info.plist; 305 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 306 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 307 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 308 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 309 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 310 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 311 | LD_RUNPATH_SEARCH_PATHS = ( 312 | "$(inherited)", 313 | "@executable_path/Frameworks", 314 | ); 315 | MARKETING_VERSION = 1.0; 316 | PRODUCT_BUNDLE_IDENTIFIER = com.aheze.SplitSheetExample; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_EMIT_LOC_STRINGS = YES; 319 | SWIFT_VERSION = 5.0; 320 | TARGETED_DEVICE_FAMILY = "1,2"; 321 | }; 322 | name = Debug; 323 | }; 324 | 3CB3F272284D207400BC03E4 /* Release */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 328 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 329 | CODE_SIGN_STYLE = Automatic; 330 | CURRENT_PROJECT_VERSION = 1; 331 | DEVELOPMENT_TEAM = YA533DMD5J; 332 | GENERATE_INFOPLIST_FILE = YES; 333 | INFOPLIST_FILE = SplitSheetExample/Info.plist; 334 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 335 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 336 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 337 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 338 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 339 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 340 | LD_RUNPATH_SEARCH_PATHS = ( 341 | "$(inherited)", 342 | "@executable_path/Frameworks", 343 | ); 344 | MARKETING_VERSION = 1.0; 345 | PRODUCT_BUNDLE_IDENTIFIER = com.aheze.SplitSheetExample; 346 | PRODUCT_NAME = "$(TARGET_NAME)"; 347 | SWIFT_EMIT_LOC_STRINGS = YES; 348 | SWIFT_VERSION = 5.0; 349 | TARGETED_DEVICE_FAMILY = "1,2"; 350 | }; 351 | name = Release; 352 | }; 353 | /* End XCBuildConfiguration section */ 354 | 355 | /* Begin XCConfigurationList section */ 356 | 3CB3F257284D207200BC03E4 /* Build configuration list for PBXProject "SplitSheetExample" */ = { 357 | isa = XCConfigurationList; 358 | buildConfigurations = ( 359 | 3CB3F26E284D207400BC03E4 /* Debug */, 360 | 3CB3F26F284D207400BC03E4 /* Release */, 361 | ); 362 | defaultConfigurationIsVisible = 0; 363 | defaultConfigurationName = Release; 364 | }; 365 | 3CB3F270284D207400BC03E4 /* Build configuration list for PBXNativeTarget "SplitSheetExample" */ = { 366 | isa = XCConfigurationList; 367 | buildConfigurations = ( 368 | 3CB3F271284D207400BC03E4 /* Debug */, 369 | 3CB3F272284D207400BC03E4 /* Release */, 370 | ); 371 | defaultConfigurationIsVisible = 0; 372 | defaultConfigurationName = Release; 373 | }; 374 | /* End XCConfigurationList section */ 375 | 376 | /* Begin XCRemoteSwiftPackageReference section */ 377 | 3CB3F274284D210500BC03E4 /* XCRemoteSwiftPackageReference "SplitSheet" */ = { 378 | isa = XCRemoteSwiftPackageReference; 379 | repositoryURL = "https://github.com/aheze/SplitSheet/"; 380 | requirement = { 381 | branch = main; 382 | kind = branch; 383 | }; 384 | }; 385 | /* End XCRemoteSwiftPackageReference section */ 386 | 387 | /* Begin XCSwiftPackageProductDependency section */ 388 | 3CB3F275284D210500BC03E4 /* SplitSheet */ = { 389 | isa = XCSwiftPackageProductDependency; 390 | package = 3CB3F274284D210500BC03E4 /* XCRemoteSwiftPackageReference "SplitSheet" */; 391 | productName = SplitSheet; 392 | }; 393 | /* End XCSwiftPackageProductDependency section */ 394 | }; 395 | rootObject = 3CB3F254284D207200BC03E4 /* Project object */; 396 | } 397 | -------------------------------------------------------------------------------- /Example/SplitSheetExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/SplitSheetExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/SplitSheetExample.xcodeproj/xcuserdata/aheze.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SplitSheetExample.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SplitSheetExample 4 | // 5 | // Created by A. Zheng (github.com/aheze) on 6/5/22. 6 | // Copyright © 2022 A. Zheng. All rights reserved. 7 | // 8 | 9 | 10 | import UIKit 11 | 12 | @main 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | // MARK: UISceneSession Lifecycle 23 | 24 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 25 | // Called when a new scene session is being created. 26 | // Use this method to select a configuration to create the new scene with. 27 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 28 | } 29 | 30 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 31 | // Called when the user discards a scene session. 32 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 33 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 34 | } 35 | 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/Assets.xcassets/Image.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "harold-wainwright-aEK8X33l7V4-unsplash (1).jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/Assets.xcassets/Image.imageset/harold-wainwright-aEK8X33l7V4-unsplash (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aheze/SplitSheet/aaff7d39086758aca11ac4bd2b54b539190a42bd/Example/SplitSheetExample/Assets.xcassets/Image.imageset/harold-wainwright-aEK8X33l7V4-unsplash (1).jpg -------------------------------------------------------------------------------- /Example/SplitSheetExample/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/SplitSheetExample/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 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIApplicationSceneManifest 6 | 7 | UIApplicationSupportsMultipleScenes 8 | 9 | UISceneConfigurations 10 | 11 | UIWindowSceneSessionRoleApplication 12 | 13 | 14 | UISceneConfigurationName 15 | Default Configuration 16 | UISceneDelegateClassName 17 | $(PRODUCT_MODULE_NAME).SceneDelegate 18 | UISceneStoryboardFile 19 | Main 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // SplitSheetExample 4 | // 5 | // Created by A. Zheng (github.com/aheze) on 6/5/22. 6 | // Copyright © 2022 A. Zheng. All rights reserved. 7 | // 8 | 9 | 10 | import UIKit 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 19 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 20 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 21 | guard let _ = (scene as? UIWindowScene) else { return } 22 | } 23 | 24 | func sceneDidDisconnect(_ scene: UIScene) { 25 | // Called as the scene is being released by the system. 26 | // This occurs shortly after the scene enters the background, or when its session is discarded. 27 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 28 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 29 | } 30 | 31 | func sceneDidBecomeActive(_ scene: UIScene) { 32 | // Called when the scene has moved from an inactive state to an active state. 33 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 34 | } 35 | 36 | func sceneWillResignActive(_ scene: UIScene) { 37 | // Called when the scene will move from an active state to an inactive state. 38 | // This may occur due to temporary interruptions (ex. an incoming phone call). 39 | } 40 | 41 | func sceneWillEnterForeground(_ scene: UIScene) { 42 | // Called as the scene transitions from the background to the foreground. 43 | // Use this method to undo the changes made on entering the background. 44 | } 45 | 46 | func sceneDidEnterBackground(_ scene: UIScene) { 47 | // Called as the scene transitions from the foreground to the background. 48 | // Use this method to save data, release shared resources, and store enough scene-specific state information 49 | // to restore the scene back to its current state. 50 | } 51 | 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Example/SplitSheetExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SplitSheetExample 4 | // 5 | // Created by A. Zheng (github.com/aheze) on 6/5/22. 6 | // Copyright © 2022 A. Zheng. All rights reserved. 7 | // 8 | 9 | import Combine 10 | import SplitSheet 11 | import UIKit 12 | 13 | enum Shared { 14 | /// Store references to Combine sinks. 15 | /// Used for observing changes in `parentSplitSheetController.$showing`. 16 | static var cancellables = Set() 17 | } 18 | 19 | class ViewController: UIViewController { 20 | let mainViewController = MainViewController() 21 | let sheetViewController = SheetViewController() 22 | lazy var splitSheetController = SplitSheetController( 23 | mainViewController: mainViewController, 24 | sheetViewController: sheetViewController 25 | ) 26 | 27 | override var childForStatusBarStyle: UIViewController? { 28 | return splitSheetController 29 | } 30 | 31 | override func viewDidLoad() { 32 | super.viewDidLoad() 33 | 34 | /// If true, `mainViewController` will shift up as the sheet is shown. 35 | splitSheetController.displaceContent = true 36 | 37 | /// Show a grabber handle. 38 | splitSheetController.showHandle = true 39 | 40 | /// The minimum sheet height. 41 | splitSheetController.minimumSheetHeight = CGFloat(400) 42 | 43 | /// When the sheet is shown and dragged within this limit, the sheet will bounce back. 44 | splitSheetController.snappingDistance = CGFloat(150) 45 | 46 | /// How long the show/hide animation takes. 47 | splitSheetController.animationDuration = CGFloat(0.6) 48 | 49 | /// If swiping up to show the sheet is allowed or not. 50 | splitSheetController.swipeUpToShowAllowed = true 51 | 52 | /// Override the status bar color. 53 | splitSheetController.statusBarStyle = UIStatusBarStyle.default 54 | 55 | /// Add the sheet. 56 | embed(splitSheetController, inside: view) 57 | } 58 | 59 | override func viewDidAppear(_ animated: Bool) { 60 | super.viewDidAppear(animated) 61 | 62 | /// Show the sheet programmatically. 63 | splitSheetController.show(true) 64 | } 65 | } 66 | 67 | class MainViewController: UIViewController { 68 | lazy var imageView: UIImageView = { 69 | /// image credits: 70 | /// https://unsplash.com/photos/aEK8X33l7V4 71 | /// https://unsplash.com/photos/bokTMevSgxY 72 | /// https://unsplash.com/photos/KZuZAaEojq4 73 | let image = UIImage(named: "Image") 74 | let imageView = UIImageView(image: image) 75 | imageView.contentMode = .scaleAspectFill 76 | imageView.clipsToBounds = true 77 | 78 | view.addSubview(imageView) 79 | imageView.pinEdgesToSuperview() 80 | return imageView 81 | }() 82 | 83 | lazy var button: UIButton = { 84 | var container = AttributeContainer() 85 | container.font = UIFont.boldSystemFont(ofSize: 32) 86 | 87 | var configuration = UIButton.Configuration.borderedProminent() 88 | configuration.buttonSize = .large 89 | 90 | let button = UIButton(configuration: configuration) 91 | button.addAction(for: .touchUpInside) { [weak parentSplitSheetController] _ in 92 | guard let parentSplitSheetController = parentSplitSheetController else { return } 93 | parentSplitSheetController.show(!parentSplitSheetController.showing) 94 | } 95 | 96 | view.addSubview(button) 97 | button.translatesAutoresizingMaskIntoConstraints = false 98 | NSLayoutConstraint.activate([ 99 | button.centerXAnchor.constraint(equalTo: view.centerXAnchor), 100 | button.centerYAnchor.constraint(equalTo: view.centerYAnchor), 101 | ]) 102 | 103 | if let parentSplitSheetController = parentSplitSheetController { 104 | parentSplitSheetController 105 | .publisher(for: \.showing) 106 | 107 | /// Called whenever `parentSplitSheetController.showing` changes. 108 | /// Note: is also called immediately - see https://stackoverflow.com/q/60568858/14351818 109 | .sink { [weak button] showing in 110 | configuration.baseBackgroundColor = showing ? UIColor.systemGreen : UIColor.systemOrange 111 | configuration.attributedTitle = AttributedString(showing ? "Sheet Shown" : "Sheet Hidden", attributes: container) 112 | button?.configuration = configuration 113 | } 114 | .store(in: &Shared.cancellables) 115 | } 116 | 117 | return button 118 | }() 119 | 120 | @objc var toggleSheet: (() -> Void)? 121 | 122 | override func viewDidLoad() { 123 | super.viewDidLoad() 124 | 125 | _ = imageView 126 | _ = button 127 | } 128 | } 129 | 130 | class SheetViewController: UIViewController { 131 | lazy var label: UILabel = { 132 | let label = UILabel() 133 | label.text = "Hi! I'm a sheet view controller. You can put anything here!" 134 | label.textAlignment = .center 135 | label.font = .preferredFont(forTextStyle: .title1) 136 | label.numberOfLines = 0 137 | 138 | view.addSubview(label) 139 | label.translatesAutoresizingMaskIntoConstraints = false 140 | NSLayoutConstraint.activate([ 141 | label.topAnchor.constraint(equalTo: view.topAnchor, constant: 64), 142 | label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24), 143 | label.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -600), 144 | label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24), 145 | ]) 146 | return label 147 | }() 148 | 149 | override func viewDidLoad() { 150 | super.viewDidLoad() 151 | 152 | view.backgroundColor = .systemBackground 153 | _ = label 154 | } 155 | } 156 | 157 | /// from https://www.biteinteractive.com/control-target-and-action-in-ios-14 158 | extension UIControl { 159 | func addAction(for event: UIControl.Event, handler: @escaping UIActionHandler) { 160 | addAction(UIAction(handler: handler), for: event) 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 A. Zheng 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 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.6 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "SplitSheet", 8 | platforms: [ 9 | .iOS(.v9), 10 | ], 11 | products: [ 12 | // Products define the executables and libraries a package produces, and make them visible to other packages. 13 | .library( 14 | name: "SplitSheet", 15 | targets: ["SplitSheet"] 16 | ), 17 | ], 18 | targets: [ 19 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 20 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 21 | .target( 22 | name: "SplitSheet", 23 | dependencies: [], 24 | path: "Sources" 25 | ), 26 | ] 27 | ) 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SplitSheet 2 | 3 | ![Header Image](Assets/Header.png) 4 | 5 | A lightweight, fully interactive split-screen sheet. 6 | 7 | - Powered by `UIScrollView` for super-smooth gestures. 8 | - Show/hide either programmatically or with a swipe gesture. 9 | - Gestures are fully interruptible. 10 | - Won't affect buttons and gestures nested in subviews. 11 | - Supports sizing detents (hidden, shown, expanded). 12 | - Fully compatible with Auto Layout self-sizing. 13 | - Super simple, no dependencies, ~300 lines of code. 14 | - Replicates iOS 15's sheet detents while supporting iOS 9+. 15 | 16 | ### Showcase 17 | 18 | | ![Click to show sheet](Assets/Click.gif) | ![Swipe between sheet detents](Assets/Detents.gif) | ![Overlay the sheet without displacing main content](Assets/Overlay.gif) | 19 | |---|---|---| 20 | 21 | 22 | ### Installation 23 | Requires iOS 9+. SplitSheet can be installed through the [Swift Package Manager](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) (recommended) or manually. 24 | 25 | 26 | 27 | 34 | 41 | 42 | 43 | 44 | 51 | 58 | 59 |
28 | 29 | Swift Package Manager 30 | 31 |
32 | Add the Package URL: 33 |
35 | 36 | Manual 37 | 38 |
39 | Drag this file into your project: 40 |
45 |
46 | 47 | ``` 48 | https://github.com/aheze/SplitSheet 49 | ``` 50 |
52 |
53 | 54 | ``` 55 | Sources/SplitSheet.swift 56 | ``` 57 |
60 | 61 | 62 | ### Usage 63 | 64 | ```swift 65 | import Combine 66 | import SplitSheet 67 | import UIKit 68 | 69 | class ViewController: UIViewController { 70 | 71 | /// Works with any view controller. 72 | let mainViewController = MainViewController() 73 | let sheetViewController = SheetViewController() 74 | lazy var splitSheetController = SplitSheetController( 75 | mainViewController: mainViewController, 76 | sheetViewController: sheetViewController 77 | ) 78 | 79 | override func viewDidLoad() { 80 | super.viewDidLoad() 81 | 82 | /// If true, `mainViewController` will shift up as the sheet is shown. 83 | splitSheetController.displaceContent = true 84 | 85 | /// Show a grabber handle. 86 | splitSheetController.showHandle = true 87 | 88 | /// The minimum sheet height. 89 | splitSheetController.minimumSheetHeight = CGFloat(400) 90 | 91 | /// When the sheet is shown and dragged within this limit, the sheet will bounce back. 92 | splitSheetController.snappingDistance = CGFloat(150) 93 | 94 | /// How long the show/hide animation takes. 95 | splitSheetController.animationDuration = CGFloat(0.6) 96 | 97 | /// If swiping up to show the sheet is allowed or not. 98 | splitSheetController.swipeUpToShowAllowed = true 99 | 100 | /// Override the status bar color. 101 | splitSheetController.statusBarStyle = UIStatusBarStyle.default 102 | 103 | /// Add the sheet. 104 | embed(splitSheetController, inside: view) 105 | } 106 | 107 | override func viewDidAppear(_ animated: Bool) { 108 | super.viewDidAppear(animated) 109 | 110 | /// Show the sheet programmatically. 111 | splitSheetController.show(true) 112 | } 113 | 114 | /// Propagate `splitSheetController`'s custom status bar to this view controller. 115 | override var childForStatusBarStyle: UIViewController? { 116 | return splitSheetController 117 | } 118 | } 119 | ``` 120 | 121 | ### Self-Sizing and Detents 122 | It's simple — if your sheet view controller's intrinsic size is larger than the `minimumSheetHeight`, a "large" detent will be added. 123 | 124 | ```swift 125 | class SheetViewController: UIViewController { 126 | override func viewDidLoad() { 127 | super.viewDidLoad() 128 | 129 | view.backgroundColor = .systemTeal 130 | view.heightAnchor.constraint(equalToConstant: 800).isActive = true 131 | } 132 | } 133 | ``` 134 | 135 | Hidden, shown, and expanded modes. 136 | 137 | 138 | Author | Contributing | Need Help? 139 | --- | --- | --- 140 | SplitSheet is made by [aheze](https://github.com/aheze). | All contributions are welcome. Just [fork](https://github.com/aheze/SplitSheet/fork) the repo, then make a pull request. | Open an [issue](https://github.com/aheze/SplitSheet/issues) or join the [Discord server](https://discord.com/invite/Pmq8fYcus2). You can also ping me on [Twitter](https://twitter.com/aheze0). Or read the source code — there's lots of comments. 141 | 142 | ### Apps Using SplitSheet 143 | 144 | [Find](http://getfind.app) is an app for finding your photos. SplitSheet is used for the photo gallery view and info sheet — download to check it out! 145 | 146 | 147 | Find App 148 | 149 | 150 | If you have an app that uses SplitSheet, just make a PR or [message me](https://twitter.com/aheze0). 151 | 152 | ### License 153 | 154 | ``` 155 | MIT License 156 | 157 | Copyright (c) 2022 A. Zheng 158 | 159 | Permission is hereby granted, free of charge, to any person obtaining a copy 160 | of this software and associated documentation files (the "Software"), to deal 161 | in the Software without restriction, including without limitation the rights 162 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 163 | copies of the Software, and to permit persons to whom the Software is 164 | furnished to do so, subject to the following conditions: 165 | 166 | The above copyright notice and this permission notice shall be included in all 167 | copies or substantial portions of the Software. 168 | 169 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 170 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 172 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 173 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 174 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 175 | SOFTWARE. 176 | ``` 177 | -------------------------------------------------------------------------------- /Sources/SplitSheet.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SplitSheet.swift 3 | // SplitSheet 4 | // 5 | // Created by A. Zheng (github.com/aheze) on 6/4/22. 6 | // Copyright © 2022 A. Zheng. All rights reserved. 7 | // 8 | // - 9 | // 10 | // MIT License 11 | // 12 | // Copyright (c) 2022 A. Zheng 13 | // 14 | // Permission is hereby granted, free of charge, to any person obtaining a copy 15 | // of this software and associated documentation files (the "Software"), to deal 16 | // in the Software without restriction, including without limitation the rights 17 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | // copies of the Software, and to permit persons to whom the Software is 19 | // furnished to do so, subject to the following conditions: 20 | // 21 | // The above copyright notice and this permission notice shall be included in all 22 | // copies or substantial portions of the Software. 23 | // 24 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 | // SOFTWARE. 31 | 32 | import UIKit 33 | 34 | public class SplitSheetController: UIViewController { 35 | // MARK: - External parameters 36 | 37 | /// The main content view controller. 38 | public let mainViewController: UIViewController 39 | 40 | /// The supplementary sheet view controller. 41 | public let sheetViewController: UIViewController 42 | 43 | /// If true, `mainViewController` will shift up as the sheet is shown. 44 | public var displaceContent = true 45 | 46 | /// Show a grabber handle. 47 | public var showHandle = true 48 | 49 | /// The minimum sheet height. 50 | public var minimumSheetHeight = CGFloat(400) 51 | 52 | /// When the sheet is shown and dragged within this limit, the sheet will bounce back. 53 | public var snappingDistance = CGFloat(150) 54 | 55 | /// How long the show/hide animation takes. 56 | public var animationDuration = CGFloat(0.6) 57 | 58 | /// If swiping up to show the sheet is allowed or not. 59 | public var swipeUpToShowAllowed = true 60 | 61 | /// Override the status bar color. 62 | public var statusBarStyle = UIStatusBarStyle.default 63 | 64 | // MARK: - State 65 | 66 | /// The current state of the sheet. `true` if shown, `false` if hidden. 67 | /// Observable with Combine. 68 | @objc public private(set) dynamic var showing = false 69 | 70 | // MARK: - Internal Properties 71 | 72 | public lazy var scrollView = UIScrollView() 73 | 74 | /// 2 "main" containers are needed to support `displaceContent` true/false. 75 | public lazy var mainPlaceholderContainerView = UIView() /// Provides a top anchor for `sheetContainerView`. 76 | public lazy var mainOuterContainerView = UIView() /// Pinned to the scroll view. 77 | public lazy var mainInnerContainerView = UIView() /// Embedded inside `mainOuterContainerView`. 78 | public lazy var sheetContainerView = UIView() 79 | public var handleView: UIView? 80 | 81 | /// Constraint to be adjusted later 82 | public lazy var mainOuterTopConstraint = mainOuterContainerView.topAnchor.constraint(equalTo: scrollView.topAnchor) 83 | public lazy var mainInnerBottomConstraint = mainInnerContainerView.bottomAnchor.constraint(equalTo: mainOuterContainerView.bottomAnchor) 84 | 85 | /// Make sure the sheet is at least as high as `minimumSheetHeight`. 86 | public lazy var sheetHeightConstraint = sheetContainerView.heightAnchor.constraint(greaterThanOrEqualToConstant: minimumSheetHeight) 87 | 88 | /// Create a new `SplitSheetController`. 89 | public init( 90 | mainViewController: UIViewController, 91 | sheetViewController: UIViewController 92 | ) { 93 | self.mainViewController = mainViewController 94 | self.sheetViewController = sheetViewController 95 | super.init(nibName: nil, bundle: nil) 96 | setup() 97 | } 98 | 99 | /// Apply `statusBarStyle`. 100 | override public var preferredStatusBarStyle: UIStatusBarStyle { 101 | return statusBarStyle 102 | } 103 | 104 | /// Dismiss the sheet after an orientation change. 105 | override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 106 | show(false) 107 | } 108 | 109 | /// Boilerplate code 110 | @available(*, unavailable) 111 | required init?(coder: NSCoder) { 112 | fatalError("You must create this view controller programmatically.") 113 | } 114 | } 115 | 116 | // MARK: - Setup 117 | 118 | public extension SplitSheetController { 119 | func setup() { 120 | // MARK: - Configuration 121 | 122 | scrollView.decelerationRate = .fast 123 | scrollView.alwaysBounceVertical = true 124 | scrollView.showsVerticalScrollIndicator = false 125 | scrollView.delegate = self 126 | if #available(iOS 11.0, *) { 127 | /// Prevent snapping to wrong offsets. 128 | scrollView.contentInsetAdjustmentBehavior = .never 129 | } 130 | 131 | updateShowing(false) 132 | 133 | // MARK: Add subviews 134 | 135 | view.addSubview(scrollView) 136 | scrollView.addSubview(mainPlaceholderContainerView) 137 | scrollView.addSubview(mainOuterContainerView) 138 | mainOuterContainerView.addSubview(mainInnerContainerView) 139 | scrollView.addSubview(sheetContainerView) 140 | 141 | // MARK: Add sub-view controllers 142 | 143 | embed(mainViewController, inside: mainInnerContainerView) 144 | embed(sheetViewController, inside: sheetContainerView) 145 | 146 | // MARK: Add constraints 147 | 148 | /// Basic pin-to-edge constraints. 149 | scrollView.pinEdgesToSuperview() 150 | 151 | /// More precise constraints. 152 | mainPlaceholderContainerView.translatesAutoresizingMaskIntoConstraints = false 153 | mainOuterContainerView.translatesAutoresizingMaskIntoConstraints = false 154 | mainInnerContainerView.translatesAutoresizingMaskIntoConstraints = false 155 | sheetContainerView.translatesAutoresizingMaskIntoConstraints = false 156 | 157 | NSLayoutConstraint.activate([ 158 | mainPlaceholderContainerView.topAnchor.constraint(equalTo: scrollView.topAnchor), 159 | mainPlaceholderContainerView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), 160 | mainPlaceholderContainerView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), 161 | mainPlaceholderContainerView.heightAnchor.constraint(equalTo: scrollView.heightAnchor), 162 | 163 | mainOuterContainerView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), 164 | mainOuterContainerView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), 165 | mainOuterContainerView.heightAnchor.constraint(equalTo: scrollView.heightAnchor), 166 | 167 | /// These constraints will be modified later in `scrollViewDidScroll`. 168 | mainOuterTopConstraint, 169 | mainInnerBottomConstraint, 170 | 171 | mainInnerContainerView.trailingAnchor.constraint(equalTo: mainOuterContainerView.trailingAnchor), /// Pin to edges. 172 | mainInnerContainerView.leadingAnchor.constraint(equalTo: mainOuterContainerView.leadingAnchor), 173 | mainInnerContainerView.topAnchor.constraint(equalTo: mainOuterContainerView.topAnchor), 174 | 175 | sheetContainerView.topAnchor.constraint(equalTo: mainPlaceholderContainerView.bottomAnchor), 176 | sheetContainerView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), 177 | sheetContainerView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), 178 | sheetContainerView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), 179 | sheetContainerView.widthAnchor.constraint(equalTo: scrollView.widthAnchor), 180 | 181 | /// Apply the minimum height constraint. 182 | sheetHeightConstraint, 183 | ]) 184 | } 185 | 186 | /// Add a handle view. 187 | func addHandle() { 188 | guard self.handleView == nil else { return } 189 | let handleView = UIView() 190 | 191 | if #available(iOS 13.0, *) { 192 | handleView.backgroundColor = .secondaryLabel 193 | } else { 194 | handleView.backgroundColor = .gray 195 | } 196 | 197 | handleView.layer.cornerRadius = 2.5 198 | sheetContainerView.addSubview(handleView) 199 | handleView.translatesAutoresizingMaskIntoConstraints = false 200 | NSLayoutConstraint.activate([ 201 | handleView.topAnchor.constraint(equalTo: sheetContainerView.topAnchor, constant: 9), 202 | handleView.centerXAnchor.constraint(equalTo: sheetContainerView.centerXAnchor), 203 | handleView.widthAnchor.constraint(equalToConstant: 36), 204 | handleView.heightAnchor.constraint(equalToConstant: 5), 205 | ]) 206 | self.handleView = handleView 207 | } 208 | } 209 | 210 | // MARK: - Update state 211 | 212 | public extension SplitSheetController { 213 | /// Show or hide the scroll sheet. 214 | func show(_ shouldShow: Bool) { 215 | updateShowing(shouldShow) 216 | 217 | UIView.animate( 218 | withDuration: animationDuration, 219 | delay: 0, 220 | usingSpringWithDamping: 1, 221 | initialSpringVelocity: 1 222 | ) { 223 | if shouldShow { 224 | self.scrollView.contentOffset.y = self.minimumSheetHeight 225 | } else { 226 | self.scrollView.contentOffset.y = 0 227 | } 228 | self.scrollView.layoutIfNeeded() /// Needed to animate constraints correctly. 229 | } 230 | } 231 | 232 | /// Update `showing` and other properties. 233 | private func updateShowing(_ showing: Bool) { 234 | self.showing = showing 235 | 236 | /// If `swipeUpToShowAllowed` is not enabled, prevent scrolling up when hidden. 237 | if !swipeUpToShowAllowed { 238 | scrollView.isScrollEnabled = showing 239 | } 240 | 241 | if showHandle { 242 | addHandle() 243 | } else if let handleView = handleView { 244 | handleView.removeFromSuperview() /// Hide the handle if it already exists. 245 | self.handleView = nil 246 | } 247 | } 248 | } 249 | 250 | // MARK: - Observe scroll view 251 | 252 | extension SplitSheetController: UIScrollViewDelegate { 253 | public func scrollViewDidScroll(_ scrollView: UIScrollView) { 254 | mainOuterTopConstraint.constant = scrollView.contentOffset.y 255 | 256 | if displaceContent { 257 | mainInnerBottomConstraint.constant = -min( 258 | scrollView.contentOffset.y, /// Shrink the main view controller's height... 259 | view.bounds.height /// ... but make sure it doesn't shrink under 0. 260 | ) 261 | } else { 262 | mainInnerBottomConstraint.constant = 0 263 | } 264 | } 265 | 266 | public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { 267 | /// The distance to the just-shown detent (shown, but not fully expanded). 268 | let distanceToShown = minimumSheetHeight - targetContentOffset.pointee.y 269 | 270 | /// The content offset where the sheet is hidden. 271 | let hiddenDetent = CGFloat(0) 272 | 273 | /// The content offset where the sheet is *just* shown. 274 | let shownDetent = minimumSheetHeight 275 | 276 | /// The content offset where the scroll view hits the bottom. 277 | let expandedDetent = scrollView.contentSize.height - scrollView.bounds.height 278 | 279 | let detents = [hiddenDetent, shownDetent, expandedDetent] 280 | let predictedContentOffset = targetContentOffset.pointee.y /// Use the system-predicted target content to take care of flicking with the finger. 281 | 282 | switch velocity.y { 283 | /// When the velocity is negative (scrolled down.) 284 | case ..<0: 285 | 286 | /// Only select smaller detents (prevents a flickering glitch.) 287 | let availableDetents = detents.filter { $0 < predictedContentOffset } 288 | let closestDetent = availableDetents.min { abs(predictedContentOffset - $0) < abs(predictedContentOffset - $1) } 289 | targetContentOffset.pointee.y = closestDetent ?? 0 /// If scrolling overshot, just hide the sheet. 290 | 291 | /// When the velocity is positive (scrolled up.) 292 | case CGFloat.leastNormalMagnitude...: 293 | 294 | /// Only select larger detents (prevents a flickering glitch.) 295 | let availableDetents = detents.filter { $0 > predictedContentOffset } 296 | let closestDetent = availableDetents.min { abs(predictedContentOffset - $0) < abs(predictedContentOffset - $1) } 297 | targetContentOffset.pointee.y = closestDetent ?? expandedDetent /// If scrolling overshot, fully expand the sheet. 298 | 299 | /// Handle velocity == 0 case. 300 | default: 301 | 302 | /// Ignore if sheet was released near the `expanded` detent. 303 | guard distanceToShown > -snappingDistance else { return } 304 | 305 | if distanceToShown < snappingDistance { 306 | targetContentOffset.pointee.y = minimumSheetHeight 307 | } else { 308 | targetContentOffset.pointee.y = 0 /// Hide if near the bottom. 309 | } 310 | } 311 | 312 | /// When the offset is 0, the sheet is hidden. Otherwise, it's shown. 313 | updateShowing(targetContentOffset.pointee.y != 0) 314 | } 315 | } 316 | 317 | public extension UIViewController { 318 | /// The parent scroll sheet controller if it exists. 319 | var parentSplitSheetController: SplitSheetController? { 320 | if let splitSheetController = parent as? SplitSheetController { 321 | return splitSheetController 322 | } else { 323 | print("[\(self)] isn't embedded in a split sheet controller.") 324 | return nil 325 | } 326 | } 327 | } 328 | 329 | // MARK: - Utilities 330 | 331 | public extension UIView { 332 | /// Pin a view to its parent. 333 | func pinEdgesToSuperview() { 334 | guard let superview = superview else { return } 335 | translatesAutoresizingMaskIntoConstraints = false 336 | NSLayoutConstraint.activate([ 337 | topAnchor.constraint(equalTo: superview.topAnchor), 338 | rightAnchor.constraint(equalTo: superview.rightAnchor), 339 | bottomAnchor.constraint(equalTo: superview.bottomAnchor), 340 | leftAnchor.constraint(equalTo: superview.leftAnchor), 341 | ]) 342 | } 343 | } 344 | 345 | public extension UIViewController { 346 | /// Add a child view controller inside a view. 347 | func embed(_ childViewController: UIViewController, inside view: UIView) { 348 | /// Add the view controller as a child 349 | addChild(childViewController) 350 | 351 | /// Insert as a subview. 352 | view.insertSubview(childViewController.view, at: 0) 353 | 354 | childViewController.view.pinEdgesToSuperview() 355 | 356 | /// Notify the child view controller. 357 | childViewController.didMove(toParent: self) 358 | } 359 | } 360 | --------------------------------------------------------------------------------