我知道:默认情况下,应用程序和视图控制器支持的界面方向设置为 iPad 惯用语的 UIInterfaceOrientationMaskAll 和 iPhone 惯用语的 UIInterfaceOrientationMaskAllButUpsideDown 。因此,当我使用单视图应用程序模板创建一个新项目时,为了在 iPhone 中执行所有方向,我在 ViewController.m 中添加了以下两个方法。它工作!
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotate
{
return YES;
}
然后我更改了 AppDelegate.m 下面方法中的一些代码,将应用程序的根视图从 UIViewController 更改为 UINavigationController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
if(myNavigationController == nil)
myNavigationController = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = self.myNavigationController;
[self.window makeKeyAndVisible];
return YES;
}
之后,我无法在 iPhone iOS6 模拟器中处理 UIInterfaceOrientationPortraitUpsideDown 。我该如何解决?我尝试在较旧的主题中搜索一些代码,但仍然无法正常工作。