Skip to content

Commit 8a3c6c8

Browse files
committed
解决按钮处于最底部时延时触发点击事件问题
解决按钮处于最底部时延时触发点击事件问题
1 parent 9deba6b commit 8a3c6c8

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

6 KB
Binary file not shown.

Example/SPAlertController/SPAlertController/SPAlertController.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,9 @@ - (void)viewWillDisappear:(BOOL)animated {
17141714

17151715
- (void)viewDidDisappear:(BOOL)animated {
17161716
[super viewDidDisappear:animated];
1717+
for(UIGestureRecognizer* gesture in self.view.window.gestureRecognizers){
1718+
gesture.delaysTouchesBegan = YES;
1719+
}
17171720
if ([self.delegate respondsToSelector:@selector(sp_alertControllerDidHide:)]) {
17181721
[self.delegate sp_alertControllerDidHide:self];
17191722
}

SPAlertController/SPAlertController.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ - (void)createFooterCellWithAction:(SPAlertAction *)action {
749749
button.backgroundColor = [UIColor clearColor];
750750
[button addTarget:self action:@selector(clickedFooterCell:) forControlEvents:UIControlEventTouchUpInside];
751751
[button addTarget:self action:@selector(touchDownFooterCell:) forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragInside];
752-
[button addTarget:self action:@selector(touchDragExitFooterCell:) forControlEvents:UIControlEventTouchDragExit | UIControlEventTouchUpOutside];
752+
[button addTarget:self action:@selector(touchDragExitFooterCell:) forControlEvents:UIControlEventTouchDragExit | UIControlEventTouchUpOutside | UIControlEventTouchCancel];
753753
[footerCell addSubview:button];
754754

755755
if (self.actions.count > 1) {
@@ -761,14 +761,6 @@ - (void)createFooterCellWithAction:(SPAlertAction *)action {
761761
}
762762
}
763763

764-
// 值得注意的是,如果按钮的位置位于控制器view的最底部,它的touchDown点击事件当长按时会有所延迟,重写这个方法可以解决这个问题。
765-
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
766-
if (isIPhoneX) {
767-
return UIRectEdgeNone;
768-
}
769-
return UIRectEdgeBottom;
770-
}
771-
772764
#pragma mark - 点击取消样式的action的方法
773765
- (void)clickedFooterCell:(UIButton *)sender {
774766
[self dismissViewControllerAnimated:YES completion:^{}];
@@ -1705,6 +1697,9 @@ - (void)viewWillAppear:(BOOL)animated {
17051697

17061698
- (void)viewDidAppear:(BOOL)animated {
17071699
[super viewDidAppear:animated];
1700+
for (UIGestureRecognizer *gesture in self.view.window.gestureRecognizers) {
1701+
gesture.delaysTouchesBegan = NO; // 解决TouchDown事件延迟
1702+
}
17081703
if ([self.delegate respondsToSelector:@selector(sp_alertControllerDidShow:)]) {
17091704
[self.delegate sp_alertControllerDidShow:self];
17101705
}
@@ -1719,6 +1714,9 @@ - (void)viewWillDisappear:(BOOL)animated {
17191714

17201715
- (void)viewDidDisappear:(BOOL)animated {
17211716
[super viewDidDisappear:animated];
1717+
for(UIGestureRecognizer* gesture in self.view.window.gestureRecognizers){
1718+
gesture.delaysTouchesBegan = YES;
1719+
}
17221720
if ([self.delegate respondsToSelector:@selector(sp_alertControllerDidHide:)]) {
17231721
[self.delegate sp_alertControllerDidHide:self];
17241722
}

0 commit comments

Comments
 (0)