What does the view controller do for me when the orientation has changed?

A simple iphone program created by a project template. View-based application with a few buttons, and I added the 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; } } 

Run the simulator in the "Portrait", change it to the right. I can get:

viewing ratings 0.00 0.00 320.00 460.00
viewing frame 0.00 20.00 320.00 460.00
view center 160.00 250.00
In portrait mode, the image size is 320x460, and its beginning is (0.20) due to the status bar.

viewing ratings 0.00 0.00 480.00 300.00
frame of view 0.00 0.00 300.00 480.00
viewing center 150.00 240.00
In the right landscape, the size of the borders changes to 480x300. However, the start of the frame is (0, 0). And the frame size is different from the borders.

In my head, I believe that these coordinates are similar to the following figures:

Portrait

Portrait

My question is: in landscape law, it seems that the beginning of the frame indicates one location, while the boundaries of "origin" refer to another. Therefore, I think that somewhere in the view controller there is some rotation. Where is it and what is it doing?

Thank you for reading this long and less clear question. :)

+4
source share
1 answer

In landscape mode, the "view content" ( controller.view ) will be changed and the transformation will be applied 90 degrees.

Since bounds represents a bounding box in the internal coordinate system, bounds.origin will always be in the upper left corner of the view itself.

However, frame is a bounding box in the outer or parent coordinate system. The parent of your view is a window that still has a start in the absolute upper left corner of the device. Therefore, your frame.origin is in this position in landscape mode.

+7
source

Source: https://habr.com/ru/post/1299614/


All Articles