In my application, I need to handle a different orientation for my ViewControllers
.
ViewController1
must support only landascape orientation. ViewController2
must support landscape + portrait orientation. I enable, in Summury project, all orientations like this:
So, I insert this code in ViewController1
:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
And I insert this code in ViewController2
:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
The problem is that ViewController1
rotates also in portrait orientation (it should support only landscape orientation).
Any idea?
Thank you all very much!
Is your viewController your rootViewController ? If not, that may be your problem.
If your rootViewController is a UINavigationController, you should know that it not forward those messages to it's topViewController. So if this is your case, i suggest that you use a subclass of UINavigationController in which you override those new methods in order to forward to the topViewController.
Before iOS 6 this works fine
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientatio n { if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) return YES;
else return NO; }
But in iOS 6 is deprecated
Now you should specify the orientations that want and select a orientation for presentation
you should write
- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
Hope it helps
Good Luck
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.