gpt4 book ai didi

iphone - 使用 CAAnimation 检测正在动画的 uiview subview 的触摸

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:03 25 4
gpt4 key购买 nike

我正在尝试检测动画 View 的 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 parentview 设置动画,一切正常。

当我为 parasiteArea 的父 View (一个 CAAnimation 由 View 的移动、 View 的比例和 View 的旋转组成)设置动画时,触摸在外面预期 subview 的边界。

更新

在大多数情况下,我设法通过使用 presentationLayer 属性和 CGPointApplyAffineTransform 进行检测(参见上面的代码)。然而,在某些情况下它仍然不起作用。

我想我需要将触摸点转换到 CAAnimation 的坐标空间。

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

最佳答案

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

关于iphone - 使用 CAAnimation 检测正在动画的 uiview subview 的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15178228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com