Reputation: 5616
I have a UIViewController
detail view which is pushed from a UITableView
in a UINavigationController
. In the UIViewController
I add a number of subviews (e.g a UITextView
, UIImageView
).
In iOS5
I used this code to stop autorotation if my picture view was enlarged :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (scrollView.isZoomed) {
return NO;
}
else {
return YES;
}
}
I am trying to achieve the same thing under iOS6
using :
- (BOOL)shouldAutorotate {
return FALSE;
}
However this method is never called and the app continues rotating.
Can anyone help ?
Upvotes: 3
Views: 8253
Reputation: 3655
If you have a Navigation Controller managing these views, the shouldAutorotate method won't be called. You would have to subclass UINavigationController and override methods shouldAutorotate and supportedIntervalOrientations.
From the docs:
Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate
Edit-----
As mentioned below by Lomax, subclassing UINavigationController is discouraged by Apple. You should try a category instead (this SO question explains it well):
@implementation UINavigationController
-(BOOL)shouldAutorotate
{
// your code
}
-(NSUInteger)supportedInterfaceOrientations
{
(...)
}
@end
Upvotes: 3