diff --git a/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate b/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate index ad1eef1..ee4722c 100644 Binary files a/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate and b/Example/stork-controller.xcodeproj/project.xcworkspace/xcuserdata/ivanvorobei.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Example/stork-controller/Frameworks/SPStorkController/SPStorkController.swift b/Example/stork-controller/Frameworks/SPStorkController/SPStorkController.swift index af68073..1848174 100755 --- a/Example/stork-controller/Frameworks/SPStorkController/SPStorkController.swift +++ b/Example/stork-controller/Frameworks/SPStorkController/SPStorkController.swift @@ -35,7 +35,7 @@ public enum SPStorkController { presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow) if translation >= presentationController.translateForDismiss * 0.4 { if !scrollView.isTracking && !scrollView.isDragging { - presentationController.dismissWithConfirmation(prepare: nil, completion: { + self.dismissWithConfirmation(controller: controller, completion: { presentationController.storkDelegate?.didDismissStorkBySwipe?() }) return @@ -58,6 +58,14 @@ public enum SPStorkController { } } + static public func dismissWithConfirmation(controller: UIViewController, completion: (()->())?) { + if let controller = self.presentationController(for: controller) { + controller.dismissWithConfirmation(prepare: nil, completion: { + print("Custom completion for confirmation. Confirmation is optional.") + }) + } + } + static public var topScrollIndicatorInset: CGFloat { return 6 } diff --git a/Example/stork-controller/ModalTableViewController.swift b/Example/stork-controller/ModalTableViewController.swift index e230ff5..5ad5a5b 100644 --- a/Example/stork-controller/ModalTableViewController.swift +++ b/Example/stork-controller/ModalTableViewController.swift @@ -49,11 +49,7 @@ class ModalTableViewController: UIViewController { } @objc func dismissAction() { - if let storkPresentationController = self.presentationController as? SPStorkPresentationController { - storkPresentationController.dismissWithConfirmation(prepare: nil, completion: { - print("Custom completion for confirmation. Confirmation is optional.") - }) - } + SPStorkController.dismissWithConfirmation(controller: self, completion: nil) } } diff --git a/Example/stork-controller/ModalViewController.swift b/Example/stork-controller/ModalViewController.swift index 1b40986..5808e8c 100644 --- a/Example/stork-controller/ModalViewController.swift +++ b/Example/stork-controller/ModalViewController.swift @@ -20,11 +20,7 @@ class ModalViewController: UIViewController { } @objc func dismissAction() { - if let storkPresentationController = self.presentationController as? SPStorkPresentationController { - storkPresentationController.dismissWithConfirmation(prepare: nil, completion: { - print("Custom completion for confirmation. Confirmation is optional.") - }) - } + SPStorkController.dismissWithConfirmation(controller: self, completion: nil) } override func viewWillAppear(_ animated: Bool) { diff --git a/README.md b/README.md index c014443..e7c9527 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,7 @@ Please, also use `SPStorkController.scrollViewDidScroll` function in scroll dele ### Confirm -For confirm closing by swipe, use `SPStorkControllerConfirmDelegate`. Implenet protocol: +For confirm closing by swipe, tap around, close button and indicator use `SPStorkControllerConfirmDelegate`. Implenet protocol: ```swift @objc public protocol SPStorkControllerConfirmDelegate: class { @@ -288,7 +288,15 @@ For confirm closing by swipe, use `SPStorkControllerConfirmDelegate`. Implenet p } ``` -and set `confirmDelegate` property to object, which protocol impleneted. Function `confirm` call if `needConfirm` set to `true` and controller try closing by swipe. Pass `isConfirmed` with result. Best options use `UIAlertController` with `.actionSheet` style for confirmation. +and set `confirmDelegate` property to object, which protocol impleneted. Function `confirm` call if `needConfirm` return true. Pass `isConfirmed` with result. Best options use `UIAlertController` with `.actionSheet` style for confirmation. + +If you use custom buttons, in the target use this code: + +```swift +SPStorkController.dismissWithConfirmation(controller: self, completion: nil) +``` + +It call `confirm` func and check result of confirmation. See example project for more details. ### Delegate diff --git a/SPStorkController.podspec b/SPStorkController.podspec index 140053b..b85c39f 100644 --- a/SPStorkController.podspec +++ b/SPStorkController.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SPStorkController" - s.version = "1.7.2" + s.version = "1.7.4" s.summary = "Very similar to the controllers displayed in Apple Music, Podcasts and Mail Apple's applications." s.homepage = "https://github.com/IvanVorobei/SPStorkController" s.source = { :git => "https://github.com/IvanVorobei/SPStorkController.git", :tag => s.version } diff --git a/Source/SPStorkController/SPStorkController.swift b/Source/SPStorkController/SPStorkController.swift index af68073..1848174 100755 --- a/Source/SPStorkController/SPStorkController.swift +++ b/Source/SPStorkController/SPStorkController.swift @@ -35,7 +35,7 @@ public enum SPStorkController { presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow) if translation >= presentationController.translateForDismiss * 0.4 { if !scrollView.isTracking && !scrollView.isDragging { - presentationController.dismissWithConfirmation(prepare: nil, completion: { + self.dismissWithConfirmation(controller: controller, completion: { presentationController.storkDelegate?.didDismissStorkBySwipe?() }) return @@ -58,6 +58,14 @@ public enum SPStorkController { } } + static public func dismissWithConfirmation(controller: UIViewController, completion: (()->())?) { + if let controller = self.presentationController(for: controller) { + controller.dismissWithConfirmation(prepare: nil, completion: { + print("Custom completion for confirmation. Confirmation is optional.") + }) + } + } + static public var topScrollIndicatorInset: CGFloat { return 6 }