我在视图中动态创建了UIImageView并进行了动画处理(从一个位置移动到另一个位置)。我写了触摸事件并尝试识别图像视图上的触摸。但是,当图像具有动画效果时,它无法识别触摸事件。识别移动对象中的触摸事件
但是,如果我触摸了我添加图像视图的初始位置,它正在识别,但动画触摸不起作用。
UIImageView *birdImage = [[UIImageView alloc] initWithFrame: CGRectMake(-67, 100, 67, 52)];
birdImage.image = [UIImage imageNamed: @"Flying_bird.png"];
birdImage.tag = 1000;
birdImage.userInteractionEnabled = YES;
[birdImage setContentMode: UIViewContentModeScaleAspectFit];
[self.view addSubview: birdImage];
[UIView animateWithDuration:10.0 delay:0.0 options: ViewAnimationOptionAllowUserInteraction animations:^{
birdImage.frame = CGRectMake(547, 100, 67, 52);
} completion:nil];
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"Tag: %d", [[touch view] tag]);
}
请任何人都可以在这帮助。
嗨Mistry,谢谢你的回应。我也试过你的代码,但没有工作。我编辑了我的问题,请查看代码并让我知道我在哪里犯错误。 – MohanVydehi 2011-05-16 11:20:14