我在視圖中動態創建了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