Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 识别移动对象中的触摸事件_Iphone_Core Animation_Uitouch - Fatal编程技术网

Iphone 识别移动对象中的触摸事件

Iphone 识别移动对象中的触摸事件,iphone,core-animation,uitouch,Iphone,Core Animation,Uitouch,我在视图中动态创建了UIImageView并设置动画(从一个地方移动到另一个地方)。我写了触摸事件,并试图识别图像视图上的触摸。但是,当图像设置动画时,它无法识别触摸事件 但是,如果我在添加图像视图的初始位置进行触摸,它会识别,但在设置触摸动画时,触摸不起作用 UIImageView *birdImage = [[UIImageView alloc] initWithFrame: CGRectMake(-67, 100, 67, 52)]; birdImage.image = [UIImage

我在视图中动态创建了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]);
}

请任何人在这方面提供帮助。

您需要在图像视图的背景层上进行点击测试。所有视图都包含CALayer,CALayer同时包含模型层和表示层。表示层是您需要访问的层:

[[imageView.layer presentationLayer] hitTest:point]

这将使图像从左向右移动。在触摸图像时,您的触摸开始方法

打电话,你可以在ToucheSStart事件中做任何事情

 UIImage *image = [UIImage imageNamed:@"image.png"];
 UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
 imageView.frame = CGRectMake(-1024, 0, 1024, 768);
 [self.view addSubview:imageView];
 [imageView release]; //Your imageView is now retained by self.view
您可能需要此方法-animateWithDuration:delay:options:animations:completion:。将当前方法替换为

 [UIView animateWithDuration:10.0
                       delay:0.0
                     options: UIViewAnimationOptionAllowUserInteraction
                  animations:^{
                      imageView.frame = CGRectMake(0, 0, 1024, 768); 
                  }
                  completion:nil];

这将在动画期间启用触摸。

嗨,米斯特里,感谢您的回复。我也试过使用你的代码,但不起作用。我已经编辑了我的问题,请看代码,让我知道我哪里做错了。