-3

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

-(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");
}

}

4

1 回答 1

3

添加UIViewAnimationOptionAllowUserInteraction到动画选项

还要确保userInteractionEnabled在图像视图上是 YES

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

于 2013-07-08T08:58:48.070 回答