我有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"];
答案 0 :(得分:2)
对于任何有兴趣的人,我解决了我的问题。只需使用NSTimer
,通过以下方式检查并更新演示文稿UIImageView
中的frame
layer
:
CGRect viewLocation = [[[imageView layer] presentationLayer] frame];
imageView.frame = CGRectMake(viewLocation.origin.x, viewLocation.origin.y, viewLocation.size.width, viewLocation.size.height);
之后,触摸可以在我的图像视图的任何地方工作: - )