【问题标题】:UIButton.frame while using UIView animationUIButton.frame 同时使用 UIView 动画
【发布时间】:2011-11-10 04:13:53
【问题描述】:

我正在使用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]。但是,如果按钮所在的帧/位置,比如说,动画的一半,与playerSquare 相交,[self showEndMenu] 就不会被调用。我不知道如何解决这个问题;如果需要,我可以提供更多代码。谢谢!

【问题讨论】:

标签: ios uibutton uianimation quartz-core


【解决方案1】:

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

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

UIView animation determine center during animation

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多