1
votes

I have a strange problem with UIInterfaceOrientation. In my project there are many different views, some of them should rotate in landscape mode, and some of them should not. The problem is that all the view which were not created using Storyboard and in which only the UIInterfaceOrientation portrait is enabled this works fine and the view does not rotate, instead all the views created using the Storyboard, even if the UIInterfaceOrientation landscape mode was disabled they keep rotating. In my Xcode project setting those checks are enabled and I cannot change them:

enter image description here

How can I completely disable the device rotation in all the different views? [Storyboard or not].

This is the code I use to disable the device orientation in all the storyboard view controller, but it does not work:

- (BOOL)shouldAutorotate {
    return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
3

3 Answers

1
votes

Try this code maybe it will work for you.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientationMask)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationMaskPortrait);
}
1
votes

The solution was to assign a UINavigationController class to the UINavigationController in the Storyboard file and to place this code in his .m file:

- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
0
votes

Please, check if in your project .plist there are more than one item for orientation or something strange. I sometimes have found that orientation has different values in plist or duplicated keys. Hope it helps