使用UIView动画后应用程序缓慢

时间:2013-06-20 19:40:04

标签: ios animation uiview ios7 xcode5

所以我有一个应用程序,我会在应用程序打开后立即为一些UI元素设置动画。这些动画是使用简单的UIView动画完成的。以下是viewDidLoad部分的示例

    //animate settings in the frame
    CGRect settingsFrame = settingsView.frame;
    settingsFrame.origin.x = -104;
    settingsFrame.origin.y = 457;
    settingsView.frame = settingsFrame;

    //animate about in the frame
    CGRect aboutFrame = aboutView.frame;
    aboutFrame.origin.x = -104;
    aboutFrame.origin.y = 457;
    aboutView.frame = aboutFrame;

这是一个被调用的相应方法部分。

CGRect settingsFrame = settingsView.frame;
settingsFrame.origin.x = 0; // new x coordinate
settingsFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
settingsView.frame = settingsFrame;

CGRect aboutFrame = aboutView.frame;
aboutFrame.origin.x = 104; // new x coordinate
aboutFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
aboutView.frame = aboutFrame;

还有4组匹配的代码可以完成动画。我的问题是,每当启用viewDidLoad部分(未注释掉)时,它会减慢我的应用程序中其他过渡到xib的过程。你们有没有想过如何保持这些动画但没有缓慢的过渡?

除此之外,我应该说这是在iOS 7和Xcode 5 Developer Preview上开发的,所以我不排除错误......

1 个答案:

答案 0 :(得分:0)

您忘记在动画块结尾处添加commitAnimations ... 在下面,你的问题将得到解决。

CGRect settingsFrame = settingsView.frame;
settingsFrame.origin.x = 0; // new x coordinate
settingsFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
settingsView.frame = settingsFrame;
**[UIView commitAnimations];**

CGRect aboutFrame = aboutView.frame;
aboutFrame.origin.x = 104; // new x coordinate
aboutFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
aboutView.frame = aboutFrame;
**[UIView commitAnimations];**