0

I have a UI where the layout works in any orientation, but specific UI elements need rotating to match the current device orientation, and the status bar should always be in the current orientation. To do this, in my view controller I have

- (BOOL)shouldAutorotate {
    return NO;
}

In my setup I do

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interfaceChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

In the selector I animate the interface changes and status bar orientation to the new device orientation. This works fine in my App, but did cause layout problems with the control centre on one occasion. I just wanted to check this is the best/correct way of achieving this?

Nick
  • 3,958
  • 4
  • 32
  • 47

1 Answers1

0

1) You can create 2 view hierarchies and change which is on screen in willRotateToInterfaceOrientation by following this link : Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?

2) Or you can handle all rotations yourself by following this link : Rotating an image 90 degrees on same position when orientation changes.

Community
  • 1
  • 1
  • The first isn't really applicable, the 2nd is what I described I have already done, I just wanted to validate that was the best approach. The approach I have described improves on the link in number 2 as I return NO from shouldAutorotate which is more efficient than returning only one interface orientation, from Apple's docs: – Nick Feb 11 '14 at 20:35
  • 'If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the topmost view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed' – Nick Feb 11 '14 at 20:36