我有一个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"];