1

以下代码有效。它很好地为所有这些组件设置动画

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 的 WIDTH 设置动画……然后吹……只有 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;
    }

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

4

1 回答 1

0

尝试改变整个框架,而不仅仅是宽度。它应该工作。

在提交动画之前放置这些行(不在块中):

self.logoImageView.frame = logoRect;
etc.

而不是使用 animate 方法尝试以这种方式使用提交动画:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
// Here some more animation settings
// Here your animations 
[UIView commitAnimations];
于 2012-05-15T08:43:59.037 回答