Ios 使用UIView动画时的UIButton.frame

Ios 使用UIView动画时的UIButton.frame,ios,uibutton,uianimation,quartz-core,Ios,Uibutton,Uianimation,Quartz Core,我正在使用UIView动画在屏幕上移动按钮。当它移动时,我有一个NSTimer运行该方法 checkForCollision 看起来是这样的: for(UIButton* b in squares) if(CGRectIntersectsRect(playerSquare.frame, b.frame)) { [self showEndMenu]; break; } [UIView beginAnimations:@"" context:nil

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

checkForCollision
看起来是这样的:

for(UIButton* b in squares)
    if(CGRectIntersectsRect(playerSquare.frame, b.frame)) {
        [self showEndMenu];
        break;
    }
[UIView beginAnimations:@"" context:nil];
[UIView setAnimationDuration:1.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
view.center = destPoint;
[UIView commitAnimations];
间隔为0.05;我希望该方法在按钮在另一条路径上移动时通知我。问题似乎是,当它检查
ui按钮b的帧时,它只看到按钮朝哪个帧移动

我将按钮设置为如下动画:

for(UIButton* b in squares)
    if(CGRectIntersectsRect(playerSquare.frame, b.frame)) {
        [self showEndMenu];
        break;
    }
[UIView beginAnimations:@"" context:nil];
[UIView setAnimationDuration:1.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
view.center = destPoint;
[UIView commitAnimations];

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

通过设置视图属性的动画来移动视图会立即将属性设置为最终值,正如您所发现的那样

你可以使用核心动画层(参见在手机上键入抱歉链接不好)获得中间值,但老实说,我没有这方面的经验。如果有人这样做,在这里看到它会很好。事实上,一个快速搜索就发现了这个问题,我想这是你想要的确切答案:)

您的另一个选择是使用计时器以迭代方式移动按钮,就像使用cocos2d移动对象一样,因此,当您每次检查位置时,您的按钮都处于实际位置。然而,这样你必须自己计算路径

可能重复的