我正在尝试检测对动画视图的 UISubview 的触摸
这是我的检测代码:
//simple but not very elegant way of getting correct frame
CGRect keepFrame = self.fishContainer.layer.frame;
self.fishContainer.layer.frame = [[self.fishContainer.layer presentationLayer] frame];
//get touch location, taking presentation layer into account. (See above)
CGPoint p = [sender locationInView:self.fishContainer];
CALayer *layer =[self.fishContainer.layer presentationLayer];
//apply relevant transform
p = CGPointApplyAffineTransform(p,layer.affineTransform);
EBLog(@"checking point %@",NSStringFromCGPoint(p));
UIView *vToRemove = nil;
//find topmost view containing touched point
for (UIView *v in self.parasites) {
EBLog(@"-BOUND %@",NSStringFromCGRect(v.frame));
if(CGRectContainsPoint(v.frame, p))
{
vToRemove = v;
}
}
//OK, we have a view. Let's remove it.
if(vToRemove)
{
EBLog(@"found one");
[vToRemove removeFromSuperview];
[self.parasites removeObject:vToRemove];
if ([self.parasites count] == 0) {
[self showWinnerScreen];
[self stopGame];
}
}
//restore view frame
self.fishContainer.layer.frame = keepFrame;
只要我不parasiteArea
为父视图设置动画,一切都会正常工作。
当我parasiteArea
为父视图设置动画时(CAAnimation
由视图的移动、视图的缩放和视图的旋转组成),触摸超出了预期子视图的范围。
更新
在大多数情况下,我设法通过使用presentationLayer
属性和 CGPointApplyAffineTransform
. 但是,在某些情况下它仍然不起作用。
我想我需要将触摸点转换为CAAnimation
.
或类似的东西?有什么建议么?