UIView animation trying to change the frame size doesn't work in iOS 8 but in iOS 7
Asked Answered
A

2

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).

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 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)

Any clue about what is happening? Or alternative?

Ataliah answered 26/9, 2014 at 8:34 Comment(1)
Note that you don't need to get the frame from the containerView.frame when overwriting all members, as you do.Wellhead
H
18

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:...

Hardecanute answered 26/9, 2014 at 9:19 Comment(1)
what should be the contrainerView if I have scrollview and uiview inside of scrollview and animations happening inside this uiview. Would it be that uiview?Gagarin
C
5

is autolayout enabled? maybe in iOS 8 some additional constrains are adding during build time

try to call [self.view layoutIfNeeded]; in animatin block, after animation code itself

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) {
        ...
    }];
Corney answered 26/9, 2014 at 8:38 Comment(3)
I add my views in storyboard, how i could disable this?Tectonic
Did [self.view layoutIfNeeded] help ? Also look how to animate view with constrints #17627302Corney
It doesn't work but I finally solved it with @LorikMalork answer thanks for your help!Tectonic

© 2022 - 2024 — McMap. All rights reserved.