当用户开始拖动scrollView时,我尝试在延迟后调用一个方法。
下面的这个块被调用,但是这个performselector中的动作定义:只有当我停止拖动scrollView时才会调用
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:self.view.frame];
sv.delegate = self;
sv.backgroundColor = [UIColor redColor];
[sv setContentSize:CGSizeMake(1000, 200)];
[self.view addSubview:sv];
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"hey");
[self performSelector:@selector(myAction) withObject:nil afterDelay:3];
}
- (void)myAction
{
NSLog(@"Called 3secondes after begin dragging");
}
我也尝试使用NSTimer和后台线程,但问题是相同的......
任何想法?
答案 0 :(得分:2)
如果您希望在仍然拖动时触发回调,则必须将其安排为Common Run Loop模式,如下所示:
[self performSelector:@selector(myAction) withObject:nil afterDelay:3 inModes:@[NSRunLoopCommonModes]];
那就是诀窍:))