ios – 当我为UIImageView设置动画时,UITapGestureRecognizer不起作用

前端之家收集整理的这篇文章主要介绍了ios – 当我为UIImageView设置动画时,UITapGestureRecognizer不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我想为UI ImageView设置动画时,添加到它的UITapGestureRecognizer无法工作.为什么???
  1. -(void) testTap:(id)sender {
  2. NSLog(@"Test tap...");
  3. }
  4.  
  5. -(void) testSlide {
  6. UITapGestureRecognizer* testTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(testTap:)] autorelease];
  7. testTap.numberOfTapsrequired = 2;
  8.  
  9. UIImageView* imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_slide"]] autorelease];
  10. [imageView setFrame:CGRectMake(40,40,200,200)];
  11. imageView.userInteractionEnabled = YES;
  12. imageView.multipleTouchEnabled = YES;
  13. [imageView addGestureRecognizer:testTap];
  14.  
  15. [self.view addSubview:imageView];
  16.  
  17.  
  18. // When I add the following code,the UITapGestureRecognizer will not work. WHY???
  19. imageView.alpha = 0;
  20. CGAffineTransform t = imageView.transform;
  21. if (CGAffineTransformIsIdentity(t)) {
  22. UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut;
  23. [UIView animateWithDuration:1.0 delay:0 options:options animations:^{
  24. imageView.alpha = 1.0;
  25. } completion:^(BOOL finished) {
  26. if (finished) {
  27. [UIView animateWithDuration:1.0 delay:2.0 options:options animations:^{
  28. imageView.alpha = 0.4;
  29. } completion:^(BOOL finished) {
  30. if (finished) {
  31. [imageView removeFromSuperview];
  32. }
  33. }];
  34. }
  35. }];
  36. }
  37. }

解决方法

您需要在动画期间允许用户交互.
  1. UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;

猜你在找的iOS相关文章