1

我正在使用UIView动画在屏幕上移动按钮。当它移动时,我有一个NSTimer正在运行的方法

checkForCollision

看起来像这样:

for(UIButton* b in squares)
    if(CGRectIntersectsRect(playerSquare.frame, b.frame)) {
        [self showEndMenu];
        break;
    }

间隔为 0.05;我希望该方法在按钮移动到另一个路径时通知我。问题似乎在于,当它检查 的框架时UIButton b,它只看到按钮正在移动的框架。

我有这样的动画按钮:

[UIView beginAnimations:@"" context:nil];
[UIView setAnimationDuration:1.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
view.center = destPoint;
[UIView commitAnimations];

因此,如果 destPoint 与 相交CGRect playerSquare.frame[self showEndMenu]则调用。但是,如果按钮所在的帧/位置,例如,动画进行到一半, intersectsplayerSquare[self showEndMenu]不会被调用。我不知道如何解决这个问题;如果需要,我可以提供更多代码。谢谢!

4

1 回答 1

2

如您所见,通过为其属性设置动画来移动视图会立即将属性设置为最终值。

您_可能_能够使用核心动画层获取中间值(参见http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Animation_Types_Timing/Articles/PropertyAnimations.html#//apple_ref/doc/ uid/TP40006672-SW1在手机上打字抱歉链接不佳)但老实说我没有任何经验。如果有人这样做,很高兴在这里看到它。事实上,快速搜索已经找到了这个问题,我认为您正在寻找的确切答案是:)

UIView 动画在动画期间确定中心

您的另一个选择是使用计时器迭代地移动按钮,就像使用 cocos2d 移动对象一样,所以当您每次检查位置时,您的按钮就是它们真正所在的位置。但是,这样您必须自己计算路径。

于 2011-11-10T07:06:36.293 回答