2
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    NSLog(@"viewDidLayoutSubviews view.height: %f", self.view.frame.size.height);
}

In the above, view.height is always 1024 regardless of what orientation the device is in. Even rotating the device will cause viewDidLayoutSubviews to be called, and it will still output 1024.

Yet the view renders fine. What the heck am I missing?

devios1
  • 33,997
  • 43
  • 149
  • 241

2 Answers2

5

When iOS performs an automatic rotation, it does not change the frame property of the root view controller's view. What it does is apply a transform and animate the transform change. To see the "actual" size of your view, check the bounds property instead of the frame property.

To quote Apple's documentation of the transform property:

Warning: If this property is not the identity transform, the value of the frame property is undefined and therefore should be ignored.

Simon Goldeen
  • 8,990
  • 3
  • 32
  • 43
  • Thank you! That seems a very bizarre choice of design. Am I to presume this is *only* the case on the root view controller? – devios1 Oct 21 '13 at 22:20
  • 1
    @chaiguy if you apply a transform to one of your views, the same thing will happen. Its frame will no longer necessarily reflect its size or position. With regard to why Apple does it this way, it is because the rotation animation is achieved through animating the transform change (Or so I assume). – Simon Goldeen Oct 21 '13 at 23:13
0

I think it's time to update in iOS8. In iOS8:

  • UIScreen is now interface oriented:
  • [UIScreen bounds] now interface-oriented
  • [UIScreen applicationFrame] now interface-oriented
  • Status bar frame notifications are interface-oriented
  • Keyboard frame notifications are interface-oriented
LiangWang
  • 6,024
  • 5
  • 35
  • 47