在scrollView中延迟滚动

时间:2013-03-19 15:32:34

标签: objective-c ipad uiscrollview uikit

是否可以延迟UIScrollView的滚动?我知道,它已经延迟了,但我想增加延迟的时间间隔。有没有办法在不覆盖handlePan:的{​​{1}}的{​​{1}}的情况下执行此操作?

1 个答案:

答案 0 :(得分: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的{​​{1}}方法中的计时器无效不到一秒不止一次......)