I have a UIView thats inside a navigation controller, I am trying to prevent this view from going into Landscape however the method I am trying to use never fires.. code is below any help would be greatly appreciated..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return NO;
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
return NO;
}
return NO;
}
This method needs to be implemented in a
UIViewController
instance, not aUIView
.Also, you are in fact returning
NO
for all orientations, which is incorrect. You need to returnYES
for at least one orientation (most commonlyUIInterfaceOrientationPortrait
).You should set
return NO;
for the parent navigation controller or on aUIViewController
, not aUIView
.Also, this works just the same with less code:
iOS 5.x
iOS 6
As of iOS 6,
shouldAutorotateToInterfaceOrientation:
is deprecated. If the view controller does not override thesupportedInterfaceOrientations
method,UIKit
obtains the default rotations from the app delegate or the app’s Info.plist file.You will need to use:
Another option is modifying Deployment Info.