1

I tried to answer to this question that is about difference between view.frame and view.bounds :

I've written this:

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Do any additional setup after loading the view, typically from a nib.

    [self showPropertiesOfLabel];

    self.label.transform = CGAffineTransformMakeRotation(M_PI * 0.25);

    [self showPropertiesOfLabel];
}

- (void) showPropertiesOfLabel {
    NSLog(@"bounds.origin.x: %f", self.label.bounds.origin.x);
    NSLog(@"bounds.origin.y: %f", self.label.bounds.origin.x);
    NSLog(@"bounds.size.width : %f", self.label.bounds.size.width);
    NSLog(@"bounds.size.height: %f", self.label.bounds.size.height);


    NSLog(@"frame.origin.x : %f", self.label.frame.origin.x);
    NSLog(@"frame.origin.y : %f", self.label.frame.origin.y);

    NSLog(@"frame.size.width : %f", self.label.frame.size.width);
    NSLog(@"frame.size.width : %f", self.label.frame.size.height);
}

But what's stroked me was the fact that my view that I called "label" after

self.label.transform = CGAffineTransformMakeRotation(M_PI * 0.25);

dissapeared! But still reporting it's frame and bounds values (rather appropriately).

The most interesting part is that if I changed angle of rotation :

self.label.transform = CGAffineTransformMakeRotation(M_PI * 0.26);

It works as it should. The view don't disappear anymore!

I've test it both on the device as in the simulator:

Here is the video of it, testing in simulator:

http://youtu.be/O6aYRt_4xsE

PS:

It looks for me like a bug.

EDIT:

It looks like this behavior (bug?) is caused by Autolayout mechanisms.

You can turn it OFF by clicking at your storyboard file and at the right of Xcode there should be tab "Show the file inspector" and uncheck this box:

Autolayout

Here is video proving that this is in fact problem with Autolayout:

http://youtu.be/HbFRlXtiZ-g

But this still don't answer the question.

Paweł Brewczynski
  • 2,665
  • 3
  • 30
  • 43

1 Answers1

0

As far as I know, the results of using "classic" approaches to alter content of view hierarchies which are subject to autolayout is more or less undefined.

So this is not actually a bug. What you need to do if you would like to change your layout progammatically, is to translate your changes into changes of the autolayout constraints. This can be done automatically by setting translatesAutoresizingMaskIntoConstraints to YES.

Please have a look at this SO Question as well!

Community
  • 1
  • 1
Toastor
  • 8,980
  • 4
  • 50
  • 82