A simple iphone program generated by project template View-based Application, with several buttons, and I added following code:
- (void) showInfo: (UIView *) view {
NSLog(@"view bounds %6.2f %6.2f %6.2f %6.2f", view.bounds.origin.x, view.bounds.origin.y, view.bounds.size.width, view.bounds.size.height);
NSLog(@"view frame %6.2f %6.2f %6.2f %6.2f", view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
NSLog(@"view center %6.2f %6.2f", view.center.x, view.center.y);
}
- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration {
switch(toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeLeft:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeRight:
[self showInfo: self.view];
break;
}
}
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation {
switch(fromInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeLeft:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeRight:
[self showInfo: self.view];
break;
}
}
Launch simulator in Portrait, change to landscape right. I can get:
view bounds 0.00 0.00 320.00 460.00
view frame 0.00 20.00 320.00 460.00
view center 160.00 250.00
In portrait, view’s size is 320×460, and it’s origin is (0,20) because of status bar.
view bounds 0.00 0.00 480.00 300.00
view frame 0.00 0.00 300.00 480.00
view center 150.00 240.00
In landscape right, bounds’ size is changed to 480×300, However, the origin of the frame is (0, 0). And the size of frame is different from bounds.
In my head, I imagine that these coordinates are like following pictures:


My question is: in landscape right, it seems that the frame’s origin points to one location while bounds’ origin points to a different one. So I think somewhere in a view controller some rotation happens. Where is it and what does it do?
Thanks for reading this long and not-so-clear question. 🙂
In landscape mode, the “content view” (
controller.view) will be resized and applied a transform of 90 degrees.Since
boundsrepresent the bounding rectangle in the internal coordinates system, thebounds.originwill always at the upper-left corner of the view itself.However,
frameis the bounding rectangle in the external, or parent, coordinates system. The parent of your view is the window, which still has the origin in the device’s absolute upper-left corner. Hence yourframe.originis at that position in landscape mode.