繁体   English   中英

iPhone-使用CABasicAnimation进行动画时,UIImageView无法接收触摸事件

[英]iPhone - Touch event is not received by UIImageView while animating using CABasicAnimation

我有一个UIImageview对象沿路径移动,并且我已经使用CABasic动画和BezierCure沿该路径移动对象,现在的问题是,如果我触摸移动的对象,则UIImageView无法识别触摸事件,但是会接收到触摸事件从主要观点来看。 有人可以帮助我解决这个问题吗? 下面是我的代码

UITouch *touch = [[event allTouches] anyObject];
if (![touch.view isEqual: beaconPose1]) {
    return;
}
[touch.view.layer removeAllAnimations];

CGPoint location = [touch locationInView: self.view];

  CGRect frame = touch.view.frame;
frame.origin.x = location.x;
frame.origin.y  = location.y;
///frame.origin.x += xDisplacement;
//frame.origin.y += yDisplacement;
touch.view.frame = frame;

-启用用户交互的代码

[beaconPose1 setUserInteractionEnabled:true];

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = 1.0f;
pathAnimation.path = beaconPose3Path.CGPath;
pathAnimation.calculationMode = kCAAnimationLinear;

CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = pathAnimation.duration;
fullRotation.repeatCount = pathAnimation.duration/fullRotation.duration;
[beaconPose1.layer addAnimation:fullRotation forKey:@"360"];
[beaconPose1.layer addAnimation:pathAnimation forKey:@"movingAnimation"];

我想出了办法

CAKeyframeAnimationCABasicAnimation下的对象将不会响应触摸事件,而是可以使用毕达哥拉斯定理计算触摸的位置是否在对象的区域内,这是我们可以做的。

恐怕当前接受的答案是错误的:

当用户将手指放在屏幕上时,所有视图都将通过触摸位置进行命中测试。 但是,在对它们进行命中测试时,需要视图的frame 但是,这已链接到modelLayer的框架,该框架是动画的终点。

您想要的是对presentationLayer命中测试,但是我想这是不可能的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM