2012-05-15 68 views
1

以下代码有效。它动画所有这些部件很好UIView animateWithDuration不适用于矩形宽度/高度动画

CGRect logoRect = self.logoImageView.frame; 
CGRect loginBackgroundRect = self.loginControlsBkImageView.frame; 
CGRect loginButtonRect = self.loginButton.frame; 
CGRect tableViewRect = self.tableView.frame; 
CGRect forgotPasswordRect = self.forgotButton.frame; 
CGRect signupButtonRect = self.signUpButton.frame; 


if (!iPhone) { 

    // ipad keyboard-on-screen re-layout 

    logoRect.origin.y-= 60; 
    loginBackgroundRect.origin.y-= 110; 
    loginButtonRect.origin.y-=110; 
    tableViewRect.origin.y-=110; 
    forgotPasswordRect.origin.y-=110; 
    signupButtonRect.origin.y-=200; 

} 
else { 

    // iphone keyboard-on-screen re-layout 

    if (portrait) { 
     logoRect.origin.y-=17; 
     logoRect.origin.x-=50; 
     loginBackgroundRect.origin.y-= 70; 
     loginButtonRect.origin.y-=70; 
     tableViewRect.origin.y-=70; 
     forgotPasswordRect.origin.y-=70; 
     //signupButtonRect.origin.y+=200; // get off screen! 
    } else { 
     logoRect.origin.y-= 30; 
     loginBackgroundRect.origin.y-= 25; 
     loginButtonRect.origin.y-=25; 
     tableViewRect.origin.y-=25; 
    } 
}  


[UIView animateWithDuration:0.2f 
         delay:0.0f 
        options:UIViewAnimationOptionCurveEaseIn 
       animations:^(void) { 
        self.logoImageView.frame = logoRect; 
        self.loginControlsBkImageView.frame = loginBackgroundRect; 
        self.loginButton.frame = loginButtonRect; 
        self.tableView.frame = tableViewRect; 
        self.forgotButton.frame = forgotPasswordRect; 
        self.signUpButton.frame = signupButtonRect; 
       } 
       completion:NULL]; 

看看下面的代码,并添加一条线(见下文),以动画logoImageView的宽度......和粉扑......只有logoImageView动画作品 - 其余的根本不动。就好像帧大小动画会导致其他所有内容在同一个动画块中不动画一样。

if (portrait) { 
     logoRect.origin.y-=17; 
     logoRect.origin.x-=50; 
     loginBackgroundRect.origin.y-= 70; 
     loginButtonRect.origin.y-=70; 
     tableViewRect.origin.y-=70; 
     forgotPasswordRect.origin.y-=70; 
     //signupButtonRect.origin.y+=200; // get off screen! 
    } else { 
     logoRect.origin.y-= 30; 
     logoRect.size.width-= 30; // <------- LINE BEING ADDED HERE 

     loginBackgroundRect.origin.y-= 25; 
     loginButtonRect.origin.y-=25; 
     tableViewRect.origin.y-=25; 
    } 

我在这里不知所措。有谁知道发生了什么事?

+0

检查其方法是歌厅首先调用或者如果框架设置后,动画片已经发射..a guess :) –

+0

它与“origin.x”,“size.width”有什么不同?这真的可能是一个时间/线程问题? – JasonGenX

+0

在动画过程中更改宽度可能会非常棘手。 –

回答

0

尝试更改整个框架,而不仅仅是宽度。它应该工作。 commiting动画(不是块)之前

把这些行:

self.logoImageView.frame = logoRect; 
etc. 

,而是采用动画的方法尝试使用提交动画是这样的:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.75]; 
// Here some more animation settings 
// Here your animations 
[UIView commitAnimations]; 
+0

不确定你的意思。我正在改变一个矩形,然后分配帧=矩形。我还应该做什么? – JasonGenX

+0

我编辑答案。 – wzbozon

+0

这正是我正在做的。看看我的动画块。 – JasonGenX