簡體   English   中英

嘗試更改幀大小的UIView動畫在iOS 8中不起作用,但在iOS 7中不起作用

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

我想調整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) {
            ...
        }];

我想要的東西:

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

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

但它開始動畫像(0,67,0,0)到(0,67,511,320)

關於發生了什么的任何線索? 還是另類?

您應該禁用預生成的約束。 最簡單的方法是使用自動調整遮罩而不是動畫視圖的約束。

containerView.translatesAutoresizingMaskIntoConstraints = YES;

你可以把這段代碼放到你的-viewDidLoad方法或者上面[UIView animateWithDuration:...

是否啟用了自動布局? 也許在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) {
        ...
    }];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM