简体   繁体   English

UIView animateWithDuration不适用于Rect宽度/高度动画

[英]UIView animateWithDuration doesn't work with Rect width/height animation

The following code works. 以下代码有效。 It animates all those components nicely 它很好地动画了所有这些组件

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];

Take the following code and add one line (see below) to animate the WIDTH of the logoImageView... and puff... only the logoImageView animation works - the rest simply doesn't move. 采取以下代码,并添加一行(请参见下文)以为logoImageView的宽度设置动画并吹泡泡...仅logoImageView动画有效-其余的完全不动。 as if the frame size animation causes everything else not to animate if in the same animation block. 就像帧大小动画在同一动画块中一样,导致其他所有内容都不进行动画处理。

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;
    }

I'm at a loss here. 我在这里茫然。 Does anyone know what's going on? 有人知道发生了什么吗?

Try to change whole frame, not just width. 尝试改变整个框架,而不仅仅是宽度。 It should work. 它应该工作。

Put these lines before commiting animation (not in block): 将这些行放在提交动画之前(不在块中):

self.logoImageView.frame = logoRect;
etc.

And instead of using animate method try to use commit animations this way: 并且不要使用动画方法,而是尝试通过这种方式使用提交动画:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM