问题描述
我有一个动画的 UIImageView
,并收到了 UITapGestureRecognizer
。问题是在设置动画时,点击手势区域不会随视图一起移动。我可以轻按视图的原始位置,然后识别轻按手势。任何人都知道如何在视图移动且不在其原始位置时识别水龙头吗?
I have a UIImageView
that is animated and receiving a UITapGestureRecognizer
. The problem is while animated, the tap gesture area doesn't move with the view. I can tap the view's original location and the tap gesture is recognized. Anyone know how to have the tap recognized while the view is moving and not at its original position?
编辑1:
这就是我的设置方式我的点击手势识别器:
Edit 1:This is how I've set up my tap gesture recognizer:
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;
自从我的动画持续了几次以来,有没有办法让手势识别器跟随我的视线秒?我错过了设置吗?
Is there a way to have the gesture recognizer follow my view on its path since my animation lasts a couple seconds? Have I missed a setting?
编辑2:
这是设置动画的代码:
Edit 2:This is my code to set up my animation:
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"];
推荐答案
对于有兴趣的人,我解决了我的问题。只需使用 NSTimer
,检查并更新 UIImageView
的框架
来自演示文稿 layer
,作者:
For anyone interested, I solved my problem. Simply use an NSTimer
, check and update the UIImageView
's frame
from the presentation layer
by:
CGRect viewLocation = [[[imageView layer] presentationLayer] frame];
imageView.frame = CGRectMake(viewLocation.origin.x, viewLocation.origin.y, viewLocation.size.width, viewLocation.size.height);
在那之后,无论我的图像视图在哪里,触摸都可以工作:-)
After that, touches work wherever my image view is :-)
这篇关于ios uiimageview轻击手势在动画期间不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!