Landscape orientation, but the value of portraiture?

I am developing an iOS application with the latest SDK.

I set the landscape orientation as a unique orientation, and I have a question about the viewController view.

This is my code:

- (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != AVCaptureVideoOrientationLandscapeRight); } - (void)deviceOrientationDidChange:(NSNotification*)notification { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (orientation == AVCaptureVideoOrientationLandscapeLeft) NSLog(@"Orientation: Landscape Left"); else if (orientation == AVCaptureVideoOrientationLandscapeRight) NSLog(@"Orientation: Landscape Right"); NSLog(@"FRAME: %@", NSStringFromCGRect(self.view.frame)); } 

And this is the log I get:

 Orientation: Landscape Right FRAME: {{0, 0}, {320, 568}} Orientation: Landscape Right FRAME: {{0, 0}, {320, 568}} 

My question is about {{0, 0}, {320, 568}} :

Why am I getting these values?

I think the correct values ​​would be {{0, 0}, {568, 320}} .

+8
ios objective-c frame
source share
4 answers

I believe that rectangular rectangles do not respond to orientation changes.

EDIT: My initial decision was too complicated for your needs. If you find the current orientation correctly, then just interpret the width of the rectangle as the height if you are in landscape mode.

+3
source share

I am adding this solution to show what happens to the frame and snapping.

I added these three methods:

 - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; CGRect bounds = [view bounds]; NSLog(@"FRAME: %@", NSStringFromCGRect(view.frame)); NSLog(@"BOUNDS: %@", NSStringFromCGRect(bounds)); } - (void)deviceOrientationDidChange:(NSNotification*)notification { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (orientation == AVCaptureVideoOrientationLandscapeLeft) NSLog(@"1. Orientation: Landscape Left"); else if (orientation == AVCaptureVideoOrientationLandscapeRight) NSLog(@"1. Orientation: Landscape Right"); NSLog(@"1. FRAME: %@", NSStringFromCGRect(self.view.frame)); NSLog(@"1. BOUNDS: %@", NSStringFromCGRect(self.view.bounds)); } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (orientation == AVCaptureVideoOrientationLandscapeLeft) NSLog(@"2. Orientation: Landscape Left"); else if (orientation == AVCaptureVideoOrientationLandscapeRight) NSLog(@"2. Orientation: Landscape Right"); NSLog(@"2. FRAME: %@", NSStringFromCGRect(self.view.frame)); NSLog(@"2. BOUNDS: %@", NSStringFromCGRect(self.view.bounds)); } - (void)viewDidLayoutSubviews { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (orientation == AVCaptureVideoOrientationLandscapeLeft) NSLog(@"3. Orientation: Landscape Left"); else if (orientation == AVCaptureVideoOrientationLandscapeRight) NSLog(@"3. Orientation: Landscape Right"); NSLog(@"3. FRAME: %@", NSStringFromCGRect(self.view.frame)); NSLog(@"3. BOUNDS: %@", NSStringFromCGRect(self.view.bounds)); } 

And here is what I get:

 FRAME: {{0, 0}, {320, 568}} BOUNDS: {{0, 0}, {320, 568}} 3. Orientation: Landscape Right 3. FRAME: {{0, 0}, {320, 568}} 3. BOUNDS: {{0, 0}, {568, 320}} 1. Orientation: Landscape Right 1. FRAME: {{0, 0}, {320, 568}} 1. BOUNDS: {{0, 0}, {568, 320}} 1. Orientation: Landscape Right 1. FRAME: {{0, 0}, {320, 568}} 1. BOUNDS: {{0, 0}, {568, 320}} 

Related changes to viewDidLayoutSubviews:

+1
source share

Use self.view.bounds instead of self.view.frame

0
source share

Change the changes in your controller view

  SKScene * scene = [MyScene sceneWithSize:skView.bounds.size]; 

replaced by

  SKScene * scene = [MyScene sceneWithSize:CGSizeMake(skView.frame.size.height, skView.frame.size.width)]; 
0
source share

All Articles