问题
I have developed a universal app I want to support all orientation for IPAD but for Iphone I just want UIInterfaceOrientationPortrait and UIInterfaceOrientationPortraitUpsideDown only for this I have
-(BOOL)shouldAutorotate {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
return NO;
}else{
return YES;
}
}
- (NSUInteger)supportedInterfaceOrientations{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
return UIInterfaceOrientationMaskPortrait;
}else{
return UIInterfaceOrientationMaskAll;
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ;
}else{
return YES;
}
}
But still is not stop the orientation in landscape
回答1:
Simply disable all other orientations except the UIInterfaceOrientationPortrait
and UIInterfaceOrientationPortraitUpsideDown
one for the iPhone from the Summary like in the description below. In the pic the Upside down is disabled please enable it. Thanks.

回答2:
For portrait upside down you have to use navigation controller
1) I created a new subclass of UINavigationController, and added shouldAutorotate and supportedInterfaceOrientation methods:
// MyNavigationController.h:
#import <UIKit/UIKit.h>
@interface MyNavigationController : UINavigationController
@end
// MyNavigationController.m:
#import "MyNavigationController.h"
@implementation MyNavigationController
...
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
...
@end
2) In the AppDelegate, I did use my new subclass to show my root ViewController (it is introScreenViewController, a UIViewController subclass) and did set the self.window.rootViewController, so it looks that:
nvc = [[MyNavigationController alloc] initWithRootViewController:introScreenViewController];
nvc.navigationBarHidden = YES;
self.window.rootViewController = nvc;
[window addSubview:nvc.view];
[window makeKeyAndVisible];
来源:https://stackoverflow.com/questions/17421300/fixed-orientation-for-iphone-in-universal-app