I’m having some trouble trying to change my view layout when rotation the device, I have my main view called OverviewViewController, this consists of 2 view that will be hidden / shown when the device is in a certain orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// do some layout stuff
NSLog(@"OverviewViewController shouldAutorotateToInterfaceOrientation");
return YES;
}
Every time I rotate my device this method is executed twice, but in any subview it’s never called, for instance;
// In OverviewViewController
_landscapeView = [[LandscapeOverviewViewController alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:_landscapeView.view];
// In LandscapeOverviewViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
NSLog(@"LandscapeOverviewViewController: shouldAutorateToInterfaceOrientation");
// Only change orientation when it's landscape
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES;
return NO;
}
Is there a reason for subviews not responding to the device orientation? The method is just never called there.
As I can see you are adding
LandscapeOverviewViewControllerview as a subView toself.view.And you want your
LandscapeOverviewViewController‘sshouldAutorotateToInterfaceOrientationto be called which will never happen.As these are called to that controller which are
pushedorpresentednot like you are doing.Solution:
You can do two things
1.
2. You can register the orientation notification in
LandscapeOverviewViewController