From 481f40519c628823eec27dab1c1bf1a194e211f6 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 23 Sep 2019 17:16:52 -0400 Subject: [PATCH] Start sheet --- .gitignore | 78 ++++++ SheetImagePicker.xcodeproj/project.pbxproj | 226 +++++++++++++++++- .../xcschemes/xcschememanagement.plist | 5 + SheetImagePicker/Detent.swift | 31 +++ .../SheetContainerViewController.swift | 89 +++++++ SheetImagePickerTest/AppDelegate.swift | 37 +++ .../AppIcon.appiconset/Contents.json | 98 ++++++++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 ++ .../Base.lproj/Main.storyboard | 24 ++ SheetImagePickerTest/Info.plist | 64 +++++ SheetImagePickerTest/SceneDelegate.swift | 53 ++++ SheetImagePickerTest/ViewController.swift | 36 +++ 13 files changed, 760 insertions(+), 12 deletions(-) create mode 100644 .gitignore create mode 100644 SheetImagePicker/Detent.swift create mode 100644 SheetImagePicker/SheetContainerViewController.swift create mode 100644 SheetImagePickerTest/AppDelegate.swift create mode 100644 SheetImagePickerTest/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 SheetImagePickerTest/Assets.xcassets/Contents.json create mode 100644 SheetImagePickerTest/Base.lproj/LaunchScreen.storyboard create mode 100644 SheetImagePickerTest/Base.lproj/Main.storyboard create mode 100644 SheetImagePickerTest/Info.plist create mode 100644 SheetImagePickerTest/SceneDelegate.swift create mode 100644 SheetImagePickerTest/ViewController.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc6431b --- /dev/null +++ b/.gitignore @@ -0,0 +1,78 @@ +.DS_Store +MyPlayground.playground/ + +### Swift ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +.build/ + +# CocoaPods - Refactored to standalone file + +# Carthage - Refactored to standalone file + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output + +### Xcode ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated + +## Various settings + +## Other + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno diff --git a/SheetImagePicker.xcodeproj/project.pbxproj b/SheetImagePicker.xcodeproj/project.pbxproj index 0658e02..cb2722e 100644 --- a/SheetImagePicker.xcodeproj/project.pbxproj +++ b/SheetImagePicker.xcodeproj/project.pbxproj @@ -8,12 +8,56 @@ /* Begin PBXBuildFile section */ D610D2D6233945AF009EB06A /* SheetImagePicker.h in Headers */ = {isa = PBXBuildFile; fileRef = D610D2D4233945AF009EB06A /* SheetImagePicker.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D610D2E3233945B9009EB06A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D610D2E2233945B9009EB06A /* AppDelegate.swift */; }; + D610D2E5233945B9009EB06A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D610D2E4233945B9009EB06A /* SceneDelegate.swift */; }; + D610D2E7233945B9009EB06A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D610D2E6233945B9009EB06A /* ViewController.swift */; }; + D610D2EA233945B9009EB06A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D610D2E8233945B9009EB06A /* Main.storyboard */; }; + D610D2EC233945BB009EB06A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D610D2EB233945BB009EB06A /* Assets.xcassets */; }; + D610D2EF233945BB009EB06A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D610D2ED233945BB009EB06A /* LaunchScreen.storyboard */; }; + D610D2F5233945C0009EB06A /* SheetImagePicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D610D2D1233945AF009EB06A /* SheetImagePicker.framework */; }; + D610D2F6233945C0009EB06A /* SheetImagePicker.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D610D2D1233945AF009EB06A /* SheetImagePicker.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + D610D2FD23394E00009EB06A /* SheetContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D610D2FC23394E00009EB06A /* SheetContainerViewController.swift */; }; + D610D2FF23395975009EB06A /* Detent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D610D2FE23395975009EB06A /* Detent.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + D610D2F7233945C0009EB06A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = D610D2C8233945AF009EB06A /* Project object */; + proxyType = 1; + remoteGlobalIDString = D610D2D0233945AF009EB06A; + remoteInfo = SheetImagePicker; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + D610D2F9233945C0009EB06A /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + D610D2F6233945C0009EB06A /* SheetImagePicker.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ D610D2D1233945AF009EB06A /* SheetImagePicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SheetImagePicker.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D610D2D4233945AF009EB06A /* SheetImagePicker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SheetImagePicker.h; sourceTree = ""; }; D610D2D5233945AF009EB06A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D610D2E0233945B9009EB06A /* SheetImagePickerTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SheetImagePickerTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; + D610D2E2233945B9009EB06A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + D610D2E4233945B9009EB06A /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + D610D2E6233945B9009EB06A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + D610D2E9233945B9009EB06A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + D610D2EB233945BB009EB06A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + D610D2EE233945BB009EB06A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + D610D2F0233945BB009EB06A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D610D2FC23394E00009EB06A /* SheetContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetContainerViewController.swift; sourceTree = ""; }; + D610D2FE23395975009EB06A /* Detent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Detent.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -24,6 +68,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + D610D2DD233945B9009EB06A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + D610D2F5233945C0009EB06A /* SheetImagePicker.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -31,7 +83,9 @@ isa = PBXGroup; children = ( D610D2D3233945AF009EB06A /* SheetImagePicker */, + D610D2E1233945B9009EB06A /* SheetImagePickerTest */, D610D2D2233945AF009EB06A /* Products */, + D610D2F4233945C0009EB06A /* Frameworks */, ); sourceTree = ""; }; @@ -39,6 +93,7 @@ isa = PBXGroup; children = ( D610D2D1233945AF009EB06A /* SheetImagePicker.framework */, + D610D2E0233945B9009EB06A /* SheetImagePickerTest.app */, ); name = Products; sourceTree = ""; @@ -47,11 +102,34 @@ isa = PBXGroup; children = ( D610D2D4233945AF009EB06A /* SheetImagePicker.h */, + D610D2FC23394E00009EB06A /* SheetContainerViewController.swift */, + D610D2FE23395975009EB06A /* Detent.swift */, D610D2D5233945AF009EB06A /* Info.plist */, ); path = SheetImagePicker; sourceTree = ""; }; + D610D2E1233945B9009EB06A /* SheetImagePickerTest */ = { + isa = PBXGroup; + children = ( + D610D2E2233945B9009EB06A /* AppDelegate.swift */, + D610D2E4233945B9009EB06A /* SceneDelegate.swift */, + D610D2E6233945B9009EB06A /* ViewController.swift */, + D610D2E8233945B9009EB06A /* Main.storyboard */, + D610D2EB233945BB009EB06A /* Assets.xcassets */, + D610D2ED233945BB009EB06A /* LaunchScreen.storyboard */, + D610D2F0233945BB009EB06A /* Info.plist */, + ); + path = SheetImagePickerTest; + sourceTree = ""; + }; + D610D2F4233945C0009EB06A /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -84,17 +162,41 @@ productReference = D610D2D1233945AF009EB06A /* SheetImagePicker.framework */; productType = "com.apple.product-type.framework"; }; + D610D2DF233945B9009EB06A /* SheetImagePickerTest */ = { + isa = PBXNativeTarget; + buildConfigurationList = D610D2F1233945BB009EB06A /* Build configuration list for PBXNativeTarget "SheetImagePickerTest" */; + buildPhases = ( + D610D2DC233945B9009EB06A /* Sources */, + D610D2DD233945B9009EB06A /* Frameworks */, + D610D2DE233945B9009EB06A /* Resources */, + D610D2F9233945C0009EB06A /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + D610D2F8233945C0009EB06A /* PBXTargetDependency */, + ); + name = SheetImagePickerTest; + productName = SheetImagePickerTest; + productReference = D610D2E0233945B9009EB06A /* SheetImagePickerTest.app */; + productType = "com.apple.product-type.application"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ D610D2C8233945AF009EB06A /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftUpdateCheck = 1100; LastUpgradeCheck = 1100; ORGANIZATIONNAME = Shadowfacts; TargetAttributes = { D610D2D0233945AF009EB06A = { CreatedOnToolsVersion = 11.0; + LastSwiftMigration = 1100; + }; + D610D2DF233945B9009EB06A = { + CreatedOnToolsVersion = 11.0; }; }; }; @@ -112,6 +214,7 @@ projectRoot = ""; targets = ( D610D2D0233945AF009EB06A /* SheetImagePicker */, + D610D2DF233945B9009EB06A /* SheetImagePickerTest */, ); }; /* End PBXProject section */ @@ -124,6 +227,16 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + D610D2DE233945B9009EB06A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D610D2EF233945BB009EB06A /* LaunchScreen.storyboard in Resources */, + D610D2EC233945BB009EB06A /* Assets.xcassets in Resources */, + D610D2EA233945B9009EB06A /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -131,11 +244,50 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D610D2FD23394E00009EB06A /* SheetContainerViewController.swift in Sources */, + D610D2FF23395975009EB06A /* Detent.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D610D2DC233945B9009EB06A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D610D2E7233945B9009EB06A /* ViewController.swift in Sources */, + D610D2E3233945B9009EB06A /* AppDelegate.swift in Sources */, + D610D2E5233945B9009EB06A /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + D610D2F8233945C0009EB06A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = D610D2D0233945AF009EB06A /* SheetImagePicker */; + targetProxy = D610D2F7233945C0009EB06A /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + D610D2E8233945B9009EB06A /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + D610D2E9233945B9009EB06A /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + D610D2ED233945BB009EB06A /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + D610D2EE233945BB009EB06A /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ D610D2D7233945AF009EB06A /* Debug */ = { isa = XCBuildConfiguration; @@ -260,6 +412,33 @@ D610D2DA233945AF009EB06A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = HGYVAQA9FW; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = SheetImagePicker/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.SheetImagePicker; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + D610D2DB233945AF009EB06A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = HGYVAQA9FW; @@ -279,27 +458,41 @@ SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; - name = Debug; + name = Release; }; - D610D2DB233945AF009EB06A /* Release */ = { + D610D2F2233945BB009EB06A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEFINES_MODULE = YES; DEVELOPMENT_TEAM = HGYVAQA9FW; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = SheetImagePicker/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + INFOPLIST_FILE = SheetImagePickerTest/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", - "@loader_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.SheetImagePicker; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = YES; + PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.SheetImagePickerTest; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + D610D2F3233945BB009EB06A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = HGYVAQA9FW; + INFOPLIST_FILE = SheetImagePickerTest/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.SheetImagePickerTest; + PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -326,6 +519,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + D610D2F1233945BB009EB06A /* Build configuration list for PBXNativeTarget "SheetImagePickerTest" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D610D2F2233945BB009EB06A /* Debug */, + D610D2F3233945BB009EB06A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = D610D2C8233945AF009EB06A /* Project object */; diff --git a/SheetImagePicker.xcodeproj/xcuserdata/shadowfacts.xcuserdatad/xcschemes/xcschememanagement.plist b/SheetImagePicker.xcodeproj/xcuserdata/shadowfacts.xcuserdatad/xcschemes/xcschememanagement.plist index 6a206a8..89f34df 100644 --- a/SheetImagePicker.xcodeproj/xcuserdata/shadowfacts.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/SheetImagePicker.xcodeproj/xcuserdata/shadowfacts.xcuserdatad/xcschemes/xcschememanagement.plist @@ -9,6 +9,11 @@ orderHint 0 + SheetImagePickerTest.xcscheme_^#shared#^_ + + orderHint + 1 + diff --git a/SheetImagePicker/Detent.swift b/SheetImagePicker/Detent.swift new file mode 100644 index 0000000..930e36a --- /dev/null +++ b/SheetImagePicker/Detent.swift @@ -0,0 +1,31 @@ +// +// Detent.swift +// SheetImagePicker +// +// Created by Shadowfacts on 9/23/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import UIKit + +public enum Detent { + case top + case middle + case bottom + case other(CGFloat) +} + +extension Detent { + func offset(in view: UIView) -> CGFloat { + switch self { + case .top: + return max(view.safeAreaInsets.top, 50) + case .middle: + return view.bounds.midY + case .bottom: + return view.bounds.height - view.safeAreaInsets.bottom - 100//max(view.safeAreaInsets.bottom, 100) + case let .other(value): + return value + } + } +} diff --git a/SheetImagePicker/SheetContainerViewController.swift b/SheetImagePicker/SheetContainerViewController.swift new file mode 100644 index 0000000..f49d70d --- /dev/null +++ b/SheetImagePicker/SheetContainerViewController.swift @@ -0,0 +1,89 @@ +// +// SheetContainerViewController.swift +// SheetImagePicker +// +// Created by Shadowfacts on 9/23/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import UIKit + +public class SheetContainerViewController: UIViewController { + + let content: UIViewController + + public var detents: [Detent] = [.bottom, .middle, .top] { + didSet { + + } + } + + var topConstraint: NSLayoutConstraint! + lazy var initialConstant: CGFloat = view.bounds.height / 2 + + public init(content: UIViewController) { + self.content = content + + super.init(nibName: nil, bundle: nil) + } + + required public init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override public func viewDidLoad() { + super.viewDidLoad() + + addChild(content) + content.didMove(toParent: self) + view.addSubview(content.view) + topConstraint = content.view.topAnchor.constraint(equalTo: view.topAnchor, constant: initialConstant) + NSLayoutConstraint.activate([ + content.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), + content.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), + topConstraint, + content.view.bottomAnchor.constraint(equalTo: view.bottomAnchor) + ]) + + let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGestureRecognized(_:))) + content.view.addGestureRecognizer(panGesture) + } + + @objc func panGestureRecognized(_ recognizer: UIPanGestureRecognizer) { + switch recognizer.state { + case .began: + initialConstant = topConstraint.constant + + case .changed: + let translation = recognizer.translation(in: content.view) + var realOffset = initialConstant + translation.y + if realOffset < view.safeAreaInsets.top { + print(realOffset) + realOffset = view.safeAreaInsets.top - realOffset / pow(CGFloat(M_E), realOffset / view.safeAreaInsets.top) + } + topConstraint.constant = realOffset + + case .ended: + if let offset = nearestDetentOffset(offset: topConstraint.constant) { + let distance = abs(topConstraint.constant - offset) + self.topConstraint.constant = offset + let velocity = recognizer.velocity(in: view) + let springVelocity = velocity.y / distance + UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: springVelocity, animations: { + self.view.layoutIfNeeded() + }) + } + + default: + return + } + } + + func nearestDetentOffset(offset: CGFloat) -> CGFloat? { + return detents.map { $0.offset(in: view) }.min { (a, b) -> Bool in + return abs(offset - a) < abs(offset - b) + } + } + +} + diff --git a/SheetImagePickerTest/AppDelegate.swift b/SheetImagePickerTest/AppDelegate.swift new file mode 100644 index 0000000..c257da8 --- /dev/null +++ b/SheetImagePickerTest/AppDelegate.swift @@ -0,0 +1,37 @@ +// +// AppDelegate.swift +// SheetImagePickerTest +// +// Created by Shadowfacts on 9/23/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/SheetImagePickerTest/Assets.xcassets/AppIcon.appiconset/Contents.json b/SheetImagePickerTest/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/SheetImagePickerTest/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/SheetImagePickerTest/Assets.xcassets/Contents.json b/SheetImagePickerTest/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/SheetImagePickerTest/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/SheetImagePickerTest/Base.lproj/LaunchScreen.storyboard b/SheetImagePickerTest/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/SheetImagePickerTest/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SheetImagePickerTest/Base.lproj/Main.storyboard b/SheetImagePickerTest/Base.lproj/Main.storyboard new file mode 100644 index 0000000..25a7638 --- /dev/null +++ b/SheetImagePickerTest/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SheetImagePickerTest/Info.plist b/SheetImagePickerTest/Info.plist new file mode 100644 index 0000000..2a3483c --- /dev/null +++ b/SheetImagePickerTest/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/SheetImagePickerTest/SceneDelegate.swift b/SheetImagePickerTest/SceneDelegate.swift new file mode 100644 index 0000000..c997598 --- /dev/null +++ b/SheetImagePickerTest/SceneDelegate.swift @@ -0,0 +1,53 @@ +// +// SceneDelegate.swift +// SheetImagePickerTest +// +// Created by Shadowfacts on 9/23/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/SheetImagePickerTest/ViewController.swift b/SheetImagePickerTest/ViewController.swift new file mode 100644 index 0000000..4bf8546 --- /dev/null +++ b/SheetImagePickerTest/ViewController.swift @@ -0,0 +1,36 @@ +// +// ViewController.swift +// SheetImagePickerTest +// +// Created by Shadowfacts on 9/23/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import UIKit +import SheetImagePicker + +class ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + + let content = UIViewController() + content.view.translatesAutoresizingMaskIntoConstraints = false + content.view.backgroundColor = .red + let sheet = SheetContainerViewController(content: content) + sheet.view.backgroundColor = .blue + + addChild(sheet) + sheet.didMove(toParent: self) + view.addSubview(sheet.view) + NSLayoutConstraint.activate([ + sheet.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), + sheet.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), + sheet.view.topAnchor.constraint(equalTo: view.topAnchor), + sheet.view.bottomAnchor.constraint(equalTo: view.bottomAnchor) + ]) + } + +} +