Iphone Objective-C块停止指令识别器
这是我的问题 我使用块在屏幕上逐个显示两个标签(一个就绪标签出现,然后消失,GO!标签出现,然后消失) 我还有一个手势识别器来检测用户是否正在拖动视图 当我的应用程序显示标签时,手势识别器停止调用它们的回调 这是我的密码:Iphone Objective-C块停止指令识别器,iphone,objective-c,ios,uigesturerecognizer,objective-c-blocks,Iphone,Objective C,Ios,Uigesturerecognizer,Objective C Blocks,这是我的问题 我使用块在屏幕上逐个显示两个标签(一个就绪标签出现,然后消失,GO!标签出现,然后消失) 我还有一个手势识别器来检测用户是否正在拖动视图 当我的应用程序显示标签时,手势识别器停止调用它们的回调 这是我的密码: [UIView animateWithDuration:1 animations:^{ readyLabel.alpha = 0; }completion:^(BOOL finished){ [readyLabel removeFromSuperview];
[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在主线程之外执行我的块,但没有结果
我可以使用performSelector:withObject:afterDelay
来避免我的标签出现问题(在第一个动画完成后显示一个标签),但我认为这有点脏
为什么我的手势识别器停止呼叫他的回叫?块对此负责吗?这是因为块动画禁用了用户交互。您应该使用
animateWithDuration:delay:options:animations:completion:
并在options
中指定UIViewAnimationOptionAllowUserInteraction
这是因为块动画禁用用户交互。您应该使用animateWithDuration:delay:options:animations:completion:
并在options
中指定uiviewmanimationoptionalowuserinteraction
这是因为UIView
使用块设置动画时会阻止UI交互。要避免这种行为,必须使用UIViewAnimationOptionAllowUserInteraction
选项:
[UIView animateWithDuration:1
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
readyLabel.alpha = 0;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
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];
}
];
}
];
这是因为,当
UIView
使用块设置动画时,它会阻止UI交互。要避免这种行为,必须使用UIViewAnimationOptionAllowUserInteraction
选项:
[UIView animateWithDuration:1
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
readyLabel.alpha = 0;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
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];
}
];
}
];