3
votes

I have a view controller(VC1) which supports rotation to landscape mode. But in next view(VC2) I just want it to appear in portrait mode only, by this I mean if user is on VC1 in landscape mode and going to VC2,then its views are setting their frames according to landscape bounds. I don't want this, I want view should appear 90 degree rotated just like it appears in the case when user is already in VC2 in portrait mode and then changes the orientation on device to landscape and VC2 don't support autorotation.

I have that noticed that this happens only when the parent view controller also does not support autorotation. If parent view does not support autorotation then child view will will appear 90 degree rotated when pushed or presented in landscape mode.

1

1 Answers

0
votes

The way I solved this was to make the whole project appear as portrait only and on views that I needed to rotate I would setup an NSNotifier in the viewDidLoad as below.

NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

I would then handle the change in orientation like this:

-(void)handleOrientationDidChange:(NSNotification *)notification
{
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    // Change view frame to fit landscape mode and rotate
} else {
    // Reset view frame to fit portrait mode and rotate back to orignal position
}

I don't know if this will fit your needs but its how I handled a situation where VC1 needed to rotate but VC2+ didn't.