如何在动画期间触摸图像?或者我能否触摸它?

时间:2013-07-08 08:56:54

标签: ios animation uiimageview touch

我试图在动画期间触摸图像,并且在触摸时我必须开始另一个动画,但是我无法在动画期间触摸图像,请指导我能否在动画期间触摸图像?如果没有那么我应该怎么做才能触摸动画图像?

-(void)cheer{
      UIEvent *event;
      UITouch *touch = [[event allTouches] anyObject];
      UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0 ,1024,80, 121)];
      [myImageView setImage:[UIImage imageNamed:@"baloon.png"]];
      [self.view addSubview:myImageView];
      myImageView.userInteractionEnabled=YES;
      [UIView animateWithDuration:10 delay:1 options:UIViewAnimationOptionAllowUserInteraction animations:^{
      [myImageView setCenter:CGPointMake(512, -1024)];

}
       completion:^(BOOL done){
         [UIView animateWithDuration:3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
          [myImageView setCenter:CGPointMake(512, -1100)];
                     }
       completion:^(BOOL done){
           NSLog(@"ended");                                                     
          }];
        }];
if (touch.view==myImageView) {
    NSLog(@"touched");
}

}

1 个答案:

答案 0 :(得分:3)

UIViewAnimationOptionAllowUserInteraction添加到动画选项

还要确保图像视图中的userInteractionEnabled为YES

编辑:您似乎正在测试在创建图像视图之前触摸的触摸视图?永远不会输入最后一个if语句。你创建一个nil事件,然后测试它的视图(将是nil)是否等于新视图,这没有意义。你想在这做什么?