我正在尝试在我的 UIImageView 设置动画时检测触摸。
触摸检测在动画开始之前工作,一旦开始
停止,但不会停止。
我试过添加 UIViewAnimationOptionAllowUserInteraction,但它
好像一点作用都没有!
谁能指出我正确的方向?
代码:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
NSLog(@"tag=%@", [NSString stringWithFormat:@"%i", touch]);
if ([touch view] == itemCoke)
{
NSLog(@"Coke Touched");
}
}
- (IBAction)removeItemButton:(id)sender {
NSLog(@"Pushed");
[UIView animateWithDuration:5
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^
{
itemCoke.transform = CGAffineTransformRotate(itemCoke.transform, (M_PI*-0.5));
itemCoke.frame = CGRectMake(50, 50, 50, 50);
}
completion:^(BOOL finished){}];
}
感谢您的任何建议!
最佳答案
交互不起作用的原因是本质上 UIImageView 不在它看起来的位置。只有 View 的 CALayer 的表示层在屏幕周围进行动画处理。 View 已经立即到达目的地。这使得交互变得更加困难。 You will likely find this answer helpful.
关于ios - UIViewAnimationOptionAllowUserInteraction 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9523981/