这是我的问题。
我使用 block 在屏幕上一一显示两个标签(一个 READY 标 checkout 现,然后消失,GO!标 checkout 现,然后消失)。
我还有一个手势识别器来检测用户是否正在拖动 View 。
当我的应用程序显示标签时,手势识别器停止调用它们的回调。
这是我的代码:
[UIView animateWithDuration:1 animations:^{
readyLabel.alpha = 0;
}completion:^(BOOL finished){
[readyLabel removeFromSuperview];
[self.view addSubview:goLabel];
[UIView animateWithDuration:1 animations:^{
goLabel.alpha = 0;
}completion:^(BOOL finished){
self.ball = [[Ball alloc] init];
[self.view addSubview:self.ball];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(moveBall:) userInfo:nil repeats:YES];
}];
}];
到目前为止,我尝试的是使用 NSThread 在主线程之外执行我的 block ,但没有结果。
我可以使用
performSelector:withObject:afterDelay
避免我的标 checkout 现问题(在第一个动画完成后显示一个标签),但我认为它有点脏。为什么我的手势识别器停止调用他的回调?区 block 是否对此负责?
最佳答案
这是因为 block 动画禁用了用户交互。您应该使用 animateWithDuration:delay:options:animations:completion:
并指定 UIViewAnimationOptionAllowUserInteraction
在 options
.
关于iphone - Objective-C block 停止 UIGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8266550/