简体   繁体   English

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

[英]UIView animation trying to change the frame size doesn't work in iOS 8 but in iOS 7

I wanted to resize an UIView, my code works perfect in iOS 7.1 but when I run it in iOS 8 it didn't work properly (I will explain below). 我想调整UIView的大小,我的代码在iOS 7.1中运行得很完美,但是当我在iOS 8中运行时,它无法正常工作(我将在下面解释)。

I have my UIView int the storyboard with values (0,67,511,320), I want to resize to full screen on iPad, so I added the following code: 我的故事板中有我的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) {
            ...
        }];

I wanted something like: 我想要的东西:

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

                |
                V
 _________________________________
|                                 |
|                                 |
|                                 |
|               A                 |
|                                 |
|                                 |
|                                 |
|                                 |
|_________________________________|

But it starts the animation like (0,67,0,0) to (0,67,511,320) 但它开始动画像(0,67,0,0)到(0,67,511,320)

Any clue about what is happening? 关于发生了什么的任何线索? Or alternative? 还是另类?

You should disable pregenerated constraints. 您应该禁用预生成的约束。 The most simple way is to use autoresizing masks instead of constraints for animating view. 最简单的方法是使用自动调整遮罩而不是动画视图的约束。

containerView.translatesAutoresizingMaskIntoConstraints = YES;

You can put this code to your -viewDidLoad method or just above [UIView animateWithDuration:... 你可以把这段代码放到你的-viewDidLoad方法或者上面[UIView animateWithDuration:...

is autolayout enabled? 是否启用了自动布局? maybe in iOS 8 some additional constrains are adding during build time 也许在iOS 8中,在构建期间会添加一些额外的约束

try to call [self.view layoutIfNeeded]; 试着调用[self.view layoutIfNeeded]; in animatin block, after animation code itself 在animatin块中,在动画代码本身之后

UPDATE 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) {
        ...
    }];

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

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