Compare commits

...

3 Commits

Author SHA1 Message Date
Ivan Vorobei e37c43c8f3 Update SPStorkController.podspec 2019-02-07 11:45:07 +03:00
Ivan Vorobei 001536c835 Fix presented and dismiss action
Now if dismiss controller - keyboard will hide without delay. Also for func `presentAsStork` added property `height`. For SPStorkPresentingAnimationController fix start sizes
2019-02-06 10:53:58 +03:00
Ivan Vorobei 5a7d01e1e4 Update to 1.4.2
Add parameter `translateForDismiss`, which customise translation for dismiss controller. Default is `240`. Rename some parametrs.
2019-02-05 09:45:53 +03:00
6 changed files with 47 additions and 32 deletions
+16 -15
View File
@@ -51,6 +51,7 @@ let controller = UIViewController()
let transitionDelegate = SPStorkTransitioningDelegate()
controller.transitioningDelegate = transitionDelegate
controller.modalPresentationStyle = .custom
controller.modalPresentationCapturesStatusBarAppearance = true
self.present(controller, animated: true, completion: nil)
```
@@ -82,26 +83,31 @@ class ModalViewController: UIViewController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewDidLoad() {
super.viewDidLoad()
self.modalPresentationCapturesStatusBarAppearance = true
}
}
```
### Parameters
- Parameter `isSwipeToDismissEnabled` enables dismissal by swipe gesture. Default is `true`:
- Parameter `customHeight` sets custom height for modal controller. Default is `nil`:
```swift
transitionDelegate.isSwipeToDismissEnabled = true
transitionDelegate.customHeight = 350
```
- Parameter `isTapAroundToDismissEnabled` enables dismissal by tapping parent controller. Default is `true`:
- Parameter `swipeToDismissEnabled` enables dismissal by swipe gesture. Default is `true`:
```swift
transitionDelegate.isTapAroundToDismissEnabled = true
transitionDelegate.swipeToDismissEnabled = true
```
- Parameter `translateForDismiss` sets how much need to swipe down to close the controller. Work only if `swipeToDismissEnabled` is true. Default is `240`:
```swift
transitionDelegate.translateForDismiss = 100
```
- Parameter `tapAroundToDismissEnabled` enables dismissal by tapping parent controller. Default is `true`:
```swift
transitionDelegate.tapAroundToDismissEnabled = true
```
- Parameter `showIndicator` shows or hides top arrow indicator. Default is `true`:
@@ -114,11 +120,6 @@ transitionDelegate.showIndicator = true
transitionDelegate.indicatorColor = UIColor.white
```
- Parameter `customHeight` sets custom height for modal controller. Default is `nil`:
```swift
transitionDelegate.customHeight = 350
```
### Snapshots
The project uses a snapshot of the screen in order to avoid compatibility and customization issues. Before controller presentation, a snapshot of the parent view is made, and size and position are changed for the snapshot. Sometimes you will need to update the screenshot of the parent view, for that use static func:
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SPStorkController"
s.version = "1.4"
s.version = "1.4.4"
s.summary = "Modal controller as mail or Apple music application"
s.homepage = "https://github.com/IvanVorobei/SPStorkController"
s.source = { :git => "https://github.com/IvanVorobei/SPStorkController.git", :tag => s.version }
@@ -23,11 +23,13 @@ import UIKit
class SPStorkPresentationController: UIPresentationController, UIGestureRecognizerDelegate {
var isSwipeToDismissEnabled: Bool = true
var isTapAroundToDismissEnabled: Bool = true
var swipeToDismissEnabled: Bool = true
var tapAroundToDismissEnabled: Bool = true
var showIndicator: Bool = true
var indicatorColor: UIColor = UIColor.init(red: 202/255, green: 201/255, blue: 207/255, alpha: 1)
var customHeight: CGFloat? = nil
var translateForDismiss: CGFloat = 240
var transitioningDelegate: SPStorkTransitioningDelegate?
var pan: UIPanGestureRecognizer?
@@ -84,7 +86,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
if self.showIndicator {
self.indicatorView.color = self.indicatorColor
let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.dismissAction))
tap.cancelsTouchesInView = false
self.indicatorView.addGestureRecognizer(tap)
presentedView.addSubview(self.indicatorView)
@@ -169,13 +171,13 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
self.snapshotViewContainer.centerXAnchor.constraint(equalTo: containerView.centerXAnchor).isActive = true
self.updateSnapshotAspectRatio()
if self.isTapAroundToDismissEnabled {
self.tap = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
if self.tapAroundToDismissEnabled {
self.tap = UITapGestureRecognizer.init(target: self, action: #selector(self.dismissAction))
self.tap?.cancelsTouchesInView = false
self.snapshotViewContainer.addGestureRecognizer(self.tap!)
}
if self.isSwipeToDismissEnabled {
if self.swipeToDismissEnabled {
self.pan = UIPanGestureRecognizer(target: self, action: #selector(self.handlePan))
self.pan!.delegate = self
self.pan!.maximumNumberOfTouches = 1
@@ -184,7 +186,9 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
}
}
@objc func handleTap() {
@objc func dismissAction() {
self.presentingViewController.view.endEditing(true)
self.presentedViewController.view.endEditing(true)
self.presentedViewController.dismiss(animated: true, completion: nil)
}
@@ -266,7 +270,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
extension SPStorkPresentationController {
@objc func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
guard gestureRecognizer.isEqual(pan), self.isSwipeToDismissEnabled else { return }
guard gestureRecognizer.isEqual(self.pan), self.swipeToDismissEnabled else { return }
switch gestureRecognizer.state {
case .began:
@@ -278,7 +282,7 @@ extension SPStorkPresentationController {
gestureRecognizer.setTranslation(CGPoint(x: 0, y: 0), in: containerView)
case .changed:
self.workGester = true
if self.isSwipeToDismissEnabled {
if self.swipeToDismissEnabled {
let translation = gestureRecognizer.translation(in: presentedView)
self.updatePresentedViewForTranslation(inVerticalDirection: translation.y)
} else {
@@ -287,7 +291,7 @@ extension SPStorkPresentationController {
case .ended:
self.workGester = false
let translation = gestureRecognizer.translation(in: presentedView).y
if translation >= 240 {
if translation >= self.translateForDismiss {
presentedViewController.dismiss(animated: true, completion: nil)
} else {
self.indicatorView.style = .arrow
@@ -31,10 +31,16 @@ final class SPStorkPresentingAnimationController: NSObject, UIViewControllerAnim
let containerView = transitionContext.containerView
containerView.addSubview(presentedViewController.view)
presentedViewController.view.frame = CGRect(x: 0, y: containerView.bounds.height, width: containerView.bounds.width, height: containerView.bounds.height)
//presentedViewController.view.frame = CGRect(x: 0, y: containerView.bounds.height, width: containerView.bounds.width, height: containerView.bounds.height)
let finalFrameForPresentedView = transitionContext.finalFrame(for: presentedViewController)
// NEW FRAMING: Testing now. Maybe correct. If remove it lines, init frame of controller will be equal container (not stork)
presentedViewController.view.frame = finalFrameForPresentedView
presentedViewController.view.frame.origin.y = containerView.bounds.height
// END NEW.
UIView.animate(
withDuration: transitionDuration(using: transitionContext),
delay: 0,
@@ -23,19 +23,21 @@ import UIKit
public final class SPStorkTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {
public var isSwipeToDismissEnabled: Bool = true
public var isTapAroundToDismissEnabled: Bool = true
public var swipeToDismissEnabled: Bool = true
public var tapAroundToDismissEnabled: Bool = true
public var showIndicator: Bool = true
public var indicatorColor: UIColor = UIColor.init(red: 202/255, green: 201/255, blue: 207/255, alpha: 1)
public var customHeight: CGFloat? = nil
public var translateForDismiss: CGFloat = 240
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
let controller = SPStorkPresentationController(presentedViewController: presented, presenting: presenting)
controller.isSwipeToDismissEnabled = self.isSwipeToDismissEnabled
controller.isTapAroundToDismissEnabled = self.isTapAroundToDismissEnabled
controller.swipeToDismissEnabled = self.swipeToDismissEnabled
controller.tapAroundToDismissEnabled = self.tapAroundToDismissEnabled
controller.showIndicator = self.showIndicator
controller.indicatorColor = self.indicatorColor
controller.customHeight = self.customHeight
controller.translateForDismiss = self.translateForDismiss
controller.transitioningDelegate = self
return controller
}
@@ -29,10 +29,12 @@ extension UIViewController {
&& presentingViewController != nil
}
public func presentAsStork(_ controller: UIViewController, complection: (() -> Void)? = nil) {
public func presentAsStork(_ controller: UIViewController, height: CGFloat? = nil, complection: (() -> Void)? = nil) {
let transitionDelegate = SPStorkTransitioningDelegate()
transitionDelegate.customHeight = height
controller.transitioningDelegate = transitionDelegate
controller.modalPresentationStyle = .custom
controller.modalPresentationCapturesStatusBarAppearance = true
self.present(controller, animated: true, completion: complection)
}
}