iOS 6.0中的界面方向

如何在iOS 6.0中使用以下方法来支持界面方向:

shouldAutorotate supportedInterfaceOrientations preferredInterfaceOrientationForPresentation 

由于iOS 6.0中不推荐使用“shouldAutorotateToInterfaceOrientation”。

请提供代码片段来支持您的答案。

谢谢。

iOS 5中的弃用方法:

 // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } 

在iOS 6中进行replace,并与上面的不推荐使用的iOS 5方法等效:

 - (BOOL) shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; } 

希望这可以帮助。


[编辑#1:添加我的UIViewController在iPhone 6.0模拟器上的XCode 4.5中成功启动肖像模式]

 #import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskPortrait; } 

[#edit 2:支持iOS 5和iOS 6的仅支持横向应用的示例代码]

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeLeft; } 

顺便说一下,您的Xcode项目设置的设置现在优先。 确保在项目设置中正确设置了“支持的界面方向”arrays。 这是我的问题。 删除了不需要的,我的应用程序就像我用Xcode 4.4.1编译时那样工作

我的应用程序有一个自定义的UINavigationController子类的实例,它提供了几个视图控制器,除了在播放video时,只能在肖像中使用,在这种情况下,我想另外允许两种风景方向。

根据@uerceg的回答,这是我的代码。

首先,我在Xcode – > Target – > Summary中启用了Portrait,Landscape Left和Landscape。

在UINavigationController子类的实现中,I #import import'ed <MediaPlayer/MediaPlayer.h>

然后我实现了这些方法:

 // Autorotation (iOS <= 5.x) - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([self modalViewController] && [[self modalViewController] isKindOfClass:[MPMoviePlayerController class]]) { // Playing Video: Anything but 'Portrait (Upside down)' is OK return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else{ // NOT Playing Video: Only 'Portrait' is OK return (interfaceOrientation == UIInterfaceOrientationPortrait); } } // Autorotation (iOS >= 6.0) - (BOOL) shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { NSUInteger orientations = UIInterfaceOrientationMaskPortrait; if ([self modalViewController] && [[self modalViewController] isKindOfClass:[MPMoviePlayerController class]]) { // Playing Video, additionally allow both landscape orientations: orientations |= UIInterfaceOrientationMaskLandscapeLeft; orientations |= UIInterfaceOrientationMaskLandscapeRight; } return orientations; } 

NicolasMiari的代码为我工作。 有一个不同的旋转我有一个UITabBarController呈现UINavigationControllers和我使用StoryBoards。 UITabBarController的子类的实现是完全一样的,并且要耐心的故事板中的标签栏控制器的类select。 即使build成后也不能立即使用。

https://devforums.apple.com/thread/165384?tstart=0

https://devforums.apple.com/thread/166544?tstart=0

在上面的线程中,有一些关于支持iOS6上的界面方向变化的例子和build议,这两个线程涉及到游戏中心视图的问题,但是应该足以让你开始。

你还应该检查UIKit下的iOS6发行说明,不幸的是我不能给你一个直接的链接,因为我是新手。

由于NDA,避免在此处发布代码

希望有所帮助