【发布时间】:2012-09-05 18:04:08
【问题描述】:
我有一个UIImageView,它是动画的并接收一个UITapGestureRecognizer。问题在于动画时,点击手势区域不会随视图移动。我可以点击视图的原始位置并且点击手势被识别。任何人都知道如何在视图移动而不是在其原始位置时识别水龙头?
编辑 1: 这就是我设置点击手势识别器的方式:
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
tapRecognizer.cancelsTouchesInView = YES;
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.delegate = (id)self;
[imageView addGestureRecognizer:tapRecognizer];
imageView.userInteractionEnabled = YES;
由于我的动画持续了几秒钟,有没有办法让手势识别器在其路径上跟随我的视图?我错过了一个设置吗?
编辑 2: 这是我设置动画的代码:
double width = backgroundImageView.frame.size.width;
double height = backgroundImageView.frame.size.height;
CGMutablePathRef path = CGPathCreateMutable();
double startX = -imageView.frame.size.width;
double startY = height/4;
double endX = 3*width;
double endY = 0;
double duration = 40;
CGPathMoveToPoint(path, NULL, startX, startY);
CGPathAddLineToPoint(path, NULL, endX, endY);
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.duration = duration;
animation.path = path;
animation.repeatCount = HUGE_VALF;
[imageView.layer addAnimation:animation forKey:@"theAnimation"];
【问题讨论】:
-
能把动画的代码展示一下吗?
-
我添加了用于设置动画的代码。
-
我尝试通过在路径上为 UIButton 设置动画来进行测试,它执行相同的操作。如果我让动画持续 30 秒,在它移动的整个过程中,我可以点击它的原始位置,它会“好像”按钮没有动画。
标签: ios animation uiimageview uitapgesturerecognizer