如何使动作识别器在animationUIImage视图中工作

我有一个图像视图中的5animation图像,并希望允许用户基于默认ID点击它们,并推到另一个视图。 我试图添加手势点击,但imageview没有检测到。

有人可以给我一些build议吗?

编辑:结束了我没有使用它,我设置了一个UIButton。

谢谢 :)

viewDidLoad中

self.defaultID = [[NSMutableArray alloc] initWithObjects:@"7",@"9",@"11",@"27",@"6",nil]; self.defaultImageCaption = [[NSMutableArray alloc] initWithObjects:@"Ver",@"Green",@"Red",@"CF",@"Dwarf",nil]; //default image imageViewTop.alpha = 1.0; imageViewBottom.alpha = 0.0; imageViewBottom = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)]; imageViewTop = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)]; singleDefaultTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDefaultTap:)]; singleDefaultTap.numberOfTouchesRequired = 1; imageViewTop.userInteractionEnabled = YES; [imageViewTop addGestureRecognizer:singleDefaultTap]; imageViewTop.tag = 2000; UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0,44,320,367)]; [topView addSubview:imageViewTop]; [self.view addSubview:imageViewTop]; [self.view addSubview:topView]; [self.view addSubview:imageViewBottom]; [self nextAnimation] 

 -(void)nextAnimation{ //picture loop imageViewTop.image = imageViewBottom.image; imageViewBottom.image = [imageArray objectAtIndex:[imageArray count] - 1]; [imageArray insertObject:imageViewBottom.image atIndex:0]; [imageArray removeLastObject]; imageViewTop.alpha = 1.0; imageViewBottom.alpha = 0.0; [UIView animateWithDuration:4.0 animations:^{ imageViewTop.alpha = 0.0; imageViewBottom.alpha = 1.0; } completion:^(BOOL completed){ [self nextAnimation:stringsize.width]; } ]; 

行动

/ /显示您的警报…

 NSLog(@"tapped"); flowerDetails = [[FlowerDetailViewController alloc] initWithNibName:@"FlowerDetailViewController" bundle:Nil] ; Fr *fr = nil; 

//推到花详细视图

这是因为当animation应用时,通过animation对精灵的任何值(在你的情况下是UIImageView)的修改不适用于精灵原件,它被应用到它的.layer.presentationLayer,真正的仍然在它的原来的地方。 在这种情况下,你可以尝试这样做:把你的手势放在整个屏幕上,当事件响应时,你检查触摸点,对presentationLayer进行hitTest,如果是,那么做你想做的事情。

我通常使用下面的代码来做到这一点。

 - ( BOOL ) areYouThere: ( CGPoint ) point { return ( [ ( ( CALayer * )sprite.layer.presentationLayer ) hitTest: point ] != nil ); } 

当调用下面的方法时,从UITouch对象获取触点

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 

我会在图像视图顶部添加一个透明的视图,并添加一个手势识别器。

真的很晚,但我一直面临同样的问题,我发现我认为是一个更好的解决scheme:

只需使用如下所示的UIViewAnimationOptionAllowUserInteraction选项:

 [UIView animateWithDuration:4.0 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ imageViewTop.alpha = 0.0; imageViewBottom.alpha = 1.0; } completion:^(BOOL completed){ [self nextAnimation:stringsize.width]; } ];