gpt4 book ai didi

objective-c - 在 scrollView 中延迟滚动

转载 作者:行者123 更新时间:2023-12-04 05:06:21 26 4
gpt4 key购买 nike

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

最佳答案

你可以试试这个:

创建一个 DelayGestureRecognizer类(class)

#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- reset 方法中的计时器无效,以防手势识别器在不到第二...)

关于objective-c - 在 scrollView 中延迟滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15503749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com