Skip to content

Commit e65b49d

Browse files
author
wangcongling
committed
add api - (void)hw_dismissAnimated:(BOOL)animated completion:(void (^)(void))completion.
now can dismiss directly.
1 parent 21b10a4 commit e65b49d

File tree

10 files changed

+56
-13
lines changed

10 files changed

+56
-13
lines changed

Demo/PanControllerExample/Base/HWBaseViewController.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ - (void)viewDidLoad {
2828
self.textfield.placeholder = @"Please type something.";
2929
self.textfield.delegate = self;
3030
[self.view addSubview:self.textfield];
31+
32+
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
33+
[closeButton setTitle:@"Tap Me To Dismiss Directly" forState:UIControlStateNormal];
34+
[closeButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
35+
closeButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];
36+
closeButton.frame = CGRectMake(20, 122, 300, 30);
37+
[closeButton addTarget:self action:@selector(didTapCloseButton) forControlEvents:UIControlEventTouchUpInside];
38+
[self.view addSubview:closeButton];
3139
}
3240

3341
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
@@ -40,6 +48,12 @@ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
4048
[self.view endEditing:YES];
4149
}
4250

51+
- (void)didTapCloseButton {
52+
[self hw_dismissAnimated:YES completion:^{
53+
54+
}];
55+
}
56+
4357
#pragma mark - HWPanModalPresentable
4458

4559
- (PanModalHeight)shortFormHeight {
@@ -82,4 +96,8 @@ - (BOOL)shouldEnableAppearanceTransition {
8296
return NO;
8397
}
8498

99+
- (NSTimeInterval)dismissalDuration {
100+
return 1.0;
101+
}
102+
85103
@end

HWPanModal.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'HWPanModal'
11-
s.version = '0.9.1'
11+
s.version = '0.9.2'
1212
s.summary = 'HWPanModal is used to present controller and drag to dismiss.'
1313

1414
# This description is used to generate tags and improve search results.

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- HWPanModal (0.8.7)
2+
- HWPanModal (0.8.9)
33
- Masonry (1.1.0)
44
- MJRefresh (3.3.1)
55
- SnapKit (5.0.1)
@@ -11,7 +11,7 @@ DEPENDENCIES:
1111
- SnapKit (~> 5.0.0)
1212

1313
SPEC REPOS:
14-
cocoapods:
14+
https://github.com/CocoaPods/Specs.git:
1515
- Masonry
1616
- MJRefresh
1717
- SnapKit
@@ -21,11 +21,11 @@ EXTERNAL SOURCES:
2121
:path: "./"
2222

2323
SPEC CHECKSUMS:
24-
HWPanModal: 611e15ece3ce63e22130d005dfc665338df059cb
24+
HWPanModal: 259f6916c706b3f63003a325ad1bdfbe913b0fdc
2525
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
2626
MJRefresh: eeda70fbf0ad277f3178cef1cd0c3532591d6237
2727
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
2828

2929
PODFILE CHECKSUM: 3046bfffa65a16097d4e0ee1bb220fa9859f7067
3030

31-
COCOAPODS: 1.10.2
31+
COCOAPODS: 1.11.2

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Special Thanks to JetBrains! I use AppCode IDE to develop my open source project
113113
### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)
114114

115115
```ruby
116-
pod 'HWPanModal', '~> 0.6.0'
116+
pod 'HWPanModal', '~> 0.9.2'
117117
```
118118

119119
## 如何使用

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ The different is `HWPanModalContentView` is just a view, and support some animat
124124
### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)
125125

126126
```ruby
127-
pod 'HWPanModal', '~> 0.8.9'
127+
pod 'HWPanModal', '~> 0.9.2'
128128
```
129129

130130
## How to use

Sources/Controller/HWPanModalPresentationController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ NS_ASSUME_NONNULL_BEGIN
2525

2626
- (void)setScrollableContentOffset:(CGPoint)offset animated:(BOOL)animated;
2727

28+
- (void)dismissAnimated:(BOOL)animated completion:(void (^)(void))completion;
29+
2830
@end
2931

3032
NS_ASSUME_NONNULL_END

Sources/Controller/HWPanModalPresentationController.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,21 @@ - (void)adjustPresentableYPos:(CGFloat)yPos {
399399
}
400400

401401
- (void)dismiss:(BOOL)isInteractive mode:(PanModalInteractiveMode)mode {
402-
self.presentedViewController.hw_panModalPresentationDelegate.interactive = isInteractive;
403-
self.presentedViewController.hw_panModalPresentationDelegate.interactiveMode = mode;
404-
[self.presentable panModalWillDismiss];
405-
[self.presentedViewController dismissViewControllerAnimated:YES completion:^{
406-
[self.presentable panModalDidDismissed];
407-
}];
402+
[self dismiss:isInteractive mode:mode animated:YES completion:nil];
403+
}
404+
405+
- (void)dismiss:(BOOL)isInteractive mode:(PanModalInteractiveMode)mode animated:(BOOL)animated completion:(void (^)(void))completion {
406+
self.presentedViewController.hw_panModalPresentationDelegate.interactive = isInteractive;
407+
self.presentedViewController.hw_panModalPresentationDelegate.interactiveMode = mode;
408+
[self.presentable panModalWillDismiss];
409+
[self.presentedViewController dismissViewControllerAnimated:animated completion:^{
410+
if (completion) completion();
411+
[self.presentable panModalDidDismissed];
412+
}];
413+
}
414+
415+
- (void)dismissAnimated:(BOOL)animated completion:(nonnull void (^)(void))completion {
416+
[self dismiss:NO mode:PanModalInteractiveModeNone animated:animated completion:completion];
408417
}
409418

410419
- (void)presentableTransitionToState:(PresentationState)state {

Sources/Presentable/HWPanModalPresentationUpdateProtocol.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@
5555
*/
5656
- (void)hw_panModalUpdateUserHitBehavior NS_SWIFT_NAME(panModalUpdateUserHitBehavior());
5757

58+
/**
59+
* call this method to dismiss your presented VC directly
60+
*/
61+
- (void)hw_dismissAnimated:(BOOL)animated completion:(void (^)(void))completion NS_SWIFT_NAME(dismissAnimated(animated:completion:));
62+
5863
@end

Sources/Presentable/UIViewController+Presentation.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ - (void)hw_panModalUpdateUserHitBehavior {
4646
[self.hw_presentedVC updateUserHitBehavior];
4747
}
4848

49+
- (void)hw_dismissAnimated:(BOOL)animated completion:(void (^)(void))completion{
50+
if (!self.hw_presentedVC) return;
51+
[self.hw_presentedVC dismissAnimated:animated completion:completion];
52+
}
53+
4954
- (HWDimmedView *)hw_dimmedView {
5055
return self.hw_presentedVC.backgroundView;
5156
}

Sources/View/PanModal/HWPanModalContentView.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ - (void)hw_panModalSetContentOffset:(CGPoint)offset animated:(BOOL)animated {
5656
[self.containerView setScrollableContentOffset:offset animated:animated];
5757
}
5858

59+
- (void)hw_dismissAnimated:(BOOL)animated completion:(void (^)(void))completion {
60+
[self dismissAnimated:animated completion:completion];
61+
}
62+
5963
- (HWDimmedView *)hw_dimmedView {
6064
return self.containerView.backgroundView;
6165
}

0 commit comments

Comments
 (0)