Skip to content

Commit 5a7d01e

Browse files
committed
Update to 1.4.2
Add parameter `translateForDismiss`, which customise translation for dismiss controller. Default is `240`. Rename some parametrs.
1 parent a1d17d9 commit 5a7d01e

4 files changed

Lines changed: 28 additions & 19 deletions

File tree

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ class ModalViewController: UIViewController {
9292

9393
### Parameters
9494

95-
- Parameter `isSwipeToDismissEnabled` enables dismissal by swipe gesture. Default is `true`:
95+
- Parameter `swipeToDismissEnabled` enables dismissal by swipe gesture. Default is `true`:
9696

9797
```swift
98-
transitionDelegate.isSwipeToDismissEnabled = true
98+
transitionDelegate.swipeToDismissEnabled = true
9999
```
100100

101-
- Parameter `isTapAroundToDismissEnabled` enables dismissal by tapping parent controller. Default is `true`:
101+
- Parameter `tapAroundToDismissEnabled` enables dismissal by tapping parent controller. Default is `true`:
102102

103103
```swift
104-
transitionDelegate.isTapAroundToDismissEnabled = true
104+
transitionDelegate.tapAroundToDismissEnabled = true
105105
```
106106

107107
- Parameter `showIndicator` shows or hides top arrow indicator. Default is `true`:
@@ -119,6 +119,11 @@ transitionDelegate.indicatorColor = UIColor.white
119119
transitionDelegate.customHeight = 350
120120
```
121121

122+
- Parameter `translateForDismiss` sets how much need to swipe down to close the controller. Work only if `swipeToDismissEnabled` is true. Default is `240`:
123+
```swift
124+
transitionDelegate.translateForDismiss = 100
125+
```
126+
122127
### Snapshots
123128

124129
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:

SPStorkController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SPStorkController"
3-
s.version = "1.4"
3+
s.version = "1.4.2"
44
s.summary = "Modal controller as mail or Apple music application"
55
s.homepage = "https://github.com/IvanVorobei/SPStorkController"
66
s.source = { :git => "https://github.com/IvanVorobei/SPStorkController.git", :tag => s.version }

Source/SPStorkController/SPStorkPresentationController.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ import UIKit
2323

2424
class SPStorkPresentationController: UIPresentationController, UIGestureRecognizerDelegate {
2525

26-
var isSwipeToDismissEnabled: Bool = true
27-
var isTapAroundToDismissEnabled: Bool = true
26+
var swipeToDismissEnabled: Bool = true
27+
var tapAroundToDismissEnabled: Bool = true
2828
var showIndicator: Bool = true
2929
var indicatorColor: UIColor = UIColor.init(red: 202/255, green: 201/255, blue: 207/255, alpha: 1)
3030
var customHeight: CGFloat? = nil
31+
var translateForDismiss: CGFloat = 240
32+
3133
var transitioningDelegate: SPStorkTransitioningDelegate?
3234

3335
var pan: UIPanGestureRecognizer?
@@ -84,7 +86,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
8486

8587
if self.showIndicator {
8688
self.indicatorView.color = self.indicatorColor
87-
let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
89+
let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.dismissAction))
8890
tap.cancelsTouchesInView = false
8991
self.indicatorView.addGestureRecognizer(tap)
9092
presentedView.addSubview(self.indicatorView)
@@ -169,13 +171,13 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
169171
self.snapshotViewContainer.centerXAnchor.constraint(equalTo: containerView.centerXAnchor).isActive = true
170172
self.updateSnapshotAspectRatio()
171173

172-
if self.isTapAroundToDismissEnabled {
173-
self.tap = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
174+
if self.tapAroundToDismissEnabled {
175+
self.tap = UITapGestureRecognizer.init(target: self, action: #selector(self.dismissAction))
174176
self.tap?.cancelsTouchesInView = false
175177
self.snapshotViewContainer.addGestureRecognizer(self.tap!)
176178
}
177179

178-
if self.isSwipeToDismissEnabled {
180+
if self.swipeToDismissEnabled {
179181
self.pan = UIPanGestureRecognizer(target: self, action: #selector(self.handlePan))
180182
self.pan!.delegate = self
181183
self.pan!.maximumNumberOfTouches = 1
@@ -184,7 +186,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
184186
}
185187
}
186188

187-
@objc func handleTap() {
189+
@objc func dismissAction() {
188190
self.presentedViewController.dismiss(animated: true, completion: nil)
189191
}
190192

@@ -266,7 +268,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
266268
extension SPStorkPresentationController {
267269

268270
@objc func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
269-
guard gestureRecognizer.isEqual(pan), self.isSwipeToDismissEnabled else { return }
271+
guard gestureRecognizer.isEqual(self.pan), self.swipeToDismissEnabled else { return }
270272

271273
switch gestureRecognizer.state {
272274
case .began:
@@ -278,7 +280,7 @@ extension SPStorkPresentationController {
278280
gestureRecognizer.setTranslation(CGPoint(x: 0, y: 0), in: containerView)
279281
case .changed:
280282
self.workGester = true
281-
if self.isSwipeToDismissEnabled {
283+
if self.swipeToDismissEnabled {
282284
let translation = gestureRecognizer.translation(in: presentedView)
283285
self.updatePresentedViewForTranslation(inVerticalDirection: translation.y)
284286
} else {
@@ -287,7 +289,7 @@ extension SPStorkPresentationController {
287289
case .ended:
288290
self.workGester = false
289291
let translation = gestureRecognizer.translation(in: presentedView).y
290-
if translation >= 240 {
292+
if translation >= self.translateForDismiss {
291293
presentedViewController.dismiss(animated: true, completion: nil)
292294
} else {
293295
self.indicatorView.style = .arrow

Source/SPStorkController/SPStorkTransitioningDelegate.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ import UIKit
2323

2424
public final class SPStorkTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {
2525

26-
public var isSwipeToDismissEnabled: Bool = true
27-
public var isTapAroundToDismissEnabled: Bool = true
26+
public var swipeToDismissEnabled: Bool = true
27+
public var tapAroundToDismissEnabled: Bool = true
2828
public var showIndicator: Bool = true
2929
public var indicatorColor: UIColor = UIColor.init(red: 202/255, green: 201/255, blue: 207/255, alpha: 1)
3030
public var customHeight: CGFloat? = nil
31+
public var translateForDismiss: CGFloat = 240
3132

3233
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
3334
let controller = SPStorkPresentationController(presentedViewController: presented, presenting: presenting)
34-
controller.isSwipeToDismissEnabled = self.isSwipeToDismissEnabled
35-
controller.isTapAroundToDismissEnabled = self.isTapAroundToDismissEnabled
35+
controller.swipeToDismissEnabled = self.swipeToDismissEnabled
36+
controller.tapAroundToDismissEnabled = self.tapAroundToDismissEnabled
3637
controller.showIndicator = self.showIndicator
3738
controller.indicatorColor = self.indicatorColor
3839
controller.customHeight = self.customHeight
40+
controller.translateForDismiss = self.translateForDismiss
3941
controller.transitioningDelegate = self
4042
return controller
4143
}

0 commit comments

Comments
 (0)