2

是否可以延迟滚动UIScrollView?我知道,它已经延迟了,但我想增加延迟的时间间隔。有没有办法在不覆盖handlePan:scrollView 的情况下做到这一点panGestureRecognizer

4

1 回答 1

3

你可以试试这个:

创建一个DelayGestureRecognizer

#import <UIKit/UIGestureRecognizerSubclass.h>

@interface DelayGestureRecognizer : UIGestureRecognizer

@end

@implementation DelayGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];

    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        self.state = UIGestureRecognizerStateFailed;
    });
}

@end

然后,当你设置你的UIScrollView

DelayGestureRecognizer *delayGestureRecognizer = [DelayGestureRecognizer new];
[scrollView addGestureRecognizer:delayGestureRecognizer];
[scrollView.panGestureRecognizer requireGestureRecognizerToFail:delayGestureRecognizer];

UIGestureRecognizer(你明白了......实际上,使用计时器并在's方法中使计时器无效可能会更好- reset,以防手势识别器在一秒钟内被多次调用......)

于 2013-03-19T16:50:27.513 回答