Reputation: 25741
I have th e following code in my uiviewcontroller.m file:
-(BOOL)shouldAutoRotate
{
return YES or NO;
}
I have tried both YES and NO but my view controller still rotates? I am using iOS 7 and the other iOS solutions I found aren't working for me either.
Upvotes: 2
Views: 5176
Reputation: 12654
It probably happens because your controller instantiated as child of UINavigationController
in view hierarchy. The UINavigationController
does not query child controllers if they want to be rotated or not.
I had the same issue; I wanted to disable autorotation, so all hierarchy of particular UINavigationController
is locked in Portrait. I ended with this class:
@implementation FixedOrientationNavigationController
- (BOOL)shouldAutorotate {
return NO;
}
@end
which I put instead of UINavigationControllr class in Storyboard for hierarchies which I need to lock Portrait. Just this, I do not need to implement shouldAutorotate
in each controller.
You may also check this link: Orientation Respectful UINavigationController, it tries to implement "orientation respectful" UINavigationController. It works, but in some cases it leads to weird results, for example, when user rotate to Landscape and then go back to the controller which should only support Portrait.
Upvotes: 8
Reputation: 161
You can also set the orientation by clicking on project name and then general ,here you can set the orientations you want and set - (BOOL)shouldAutorotate { return NO; } Hope you got.
Upvotes: 0