尝试更改帧大小的UIView动画在iOS 8中不起作用,但在iOS 7中不起作用

ƒer*_*lle 7 objective-c uiview uianimation ios ios8

我想调整UIView的大小,我的代码在iOS 7.1中运行得很完美,但是当我在iOS 8中运行时,它无法正常工作(我将在下面解释).

我的故事板中有我的UIView值(0,67,511,320),我想在iPad上调整到全屏,所以我添加了以下代码:

        [UIView animateWithDuration:0.5 animations:^{

            CGRect frame = containerView.frame;
            frame.origin.x = 0;
            frame.origin.y = 67;
            frame.size.height = 643;
            frame.size.width = 1024;
            containerView.frame = frame;
            ...

        }completion:^(BOOL finished) {
            ...
        }];
Run Code Online (Sandbox Code Playgroud)

我想要的东西:

 _________________________________
|           |                     |
|           |                     |
|     A     |                     |
|___________|                     |
|                                 |
|                BACKGROUND       |
|                                 |
|                                 |
|_________________________________|

                |
                V
 _________________________________
|                                 |
|                                 |
|                                 |
|               A                 |
|                                 |
|                                 |
|                                 |
|                                 |
|_________________________________|
Run Code Online (Sandbox Code Playgroud)

但它开始动画像(0,67,0,0)到(0,67,511,320)

关于发生了什么的任何线索?还是另类?

Lor*_*rik 17

您应该禁用预生成的约束.最简单的方法是使用自动调整遮罩而不是动画视图的约束.

containerView.translatesAutoresizingMaskIntoConstraints = YES;
Run Code Online (Sandbox Code Playgroud)

您可以将此代码放入您的-viewDidLoad方法或上面[UIView animateWithDuration:...


Rom*_*oma 5

是否启用了自动布局?也许在iOS 8中,在构建期间会添加一些额外的约束

尝试[self.view layoutIfNeeded];在动画代码本身之后调用animatin块

UPDATE

__block CGRect frame = containerView.frame;
frame.origin.x = 0;
frame.origin.y = 67;
frame.size.height = 643;
frame.size.width = 1024;

[UIView animateWithDuration:0.5 animations:^{

        containerView.frame = frame;
        ...

    }completion:^(BOOL finished) {
        ...
    }];
Run Code Online (Sandbox Code Playgroud)