3

我正在尝试检测对动画视图的 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.

或类似的东西?有什么建议么?

4

1 回答 1

0

我最终使用UIView animateWithDuration而不是CAAninmation. 就我的目的而言,有限的动画可能就足够了。

于 2013-03-12T08:06:06.240 回答