In my app I have multiple views, some views need to support both portrait and landscape, while other views need to support portrait only. Thus, in the project summary, I have all selected all orientations.
The below code worked to disable landscape mode on a given view controller prior to iOS 6:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Since shouldAutorotateToInterfaceOrientation was deprecated in iOS6 I've replaced the above with:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMask.Portrait;
}
This method is correctly called when the view appears (I can set a breakpoint to ensure this), but the interface still rotates to landscape mode regardless of the fact that I'm returning the mask for portrait modes only. What am I doing wrong?
It seems that it's currently impossible to build an app that has different orientation requirements per view. It seems to only adhere to the orientations specified in the project summary.
try change this code in AppDelegate.m
this is the complete answer
shouldAutorotateToInterfaceOrientation not being called in iOS 6
XD
Try add
shouldAutorotate
methodmy solution : subclassed
UINavigationController
and set it aswindow.rootViewController
the top viewcontroller of the hierarchy will take control of the orientation , some code examples : subclassed UINavigationController
As stated by others if you're using a UINavigationController and you want to customize various views you'll want to subclass the UINavigationController and make sure you have these two components:
Then in any view that is a portrait only you would include:
And in any view that is everything but upside down:
If you are using
UINavigationController
, you have to implementshouldAutorotate
andsupportedInterfaceOrientations
in subclass ofUINavigationController
.These are able to control by two steps, if
shouldAutorotate
returns YES then effectivesupportedInterfaceOrientations
. It's a very nice combination.This example, my mostly views are Portrait except CoverFlowView and PreviewView. The CoverFlowView transfer to PreviewView, PreviewView wants to follow CoverFlowCView's rotation.
The best way I think is to do a Category rather than subclassing
UINavigationController
orUITabbarController
your UINavigationController+Rotation.h
your UINavigationController+Rotation.m
Try to make all your controller import this category and this work like a charm. You can even make a controller not rotating and pushing another controller that will rotate.