iOS 7界面方向

我有一个应用程序,总是以纵向模式显示。

但在某个地方,我有一个媒体画廊,必须支持景观。

项目中默认支持的方向是纵向。 因为这个画廊只是在肖像模式下显示。

如果我更改项目设置以纵向和横向显示画廊工作正常,但我不能控制其他viewControllers只显示在纵向。

我尝试了几个像shouldAutoRotate但没有人工作的方法。

任何意识如何解决?

问候

编辑:

解决了 :)

首先我configuration了项目来支持所有的方向。 然后我将这个方法添加到AppDelegate.m:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape; } 

在此之后,我所做的就是阻止每个视图控制器中的方向,而不是那些我想要在风景和肖像中定位的方向。

阻止方向的代码(iOS 7):

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

感谢所有回答我的人:)

在我的iPhone应用程序中,它只支持纵向视图,但是按照需求只需要支持横向视图,那时候我用下面的方法和它的帮助我:

在你的应用程序委托.h

 @interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { BOOL flagOrientationAll; } @property (assign) BOOL flagOrientationAll; 

在您的应用程序委托.m文件中添加以下方法

 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ //NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow"); if([UICommonUtils isiPad]){ return UIInterfaceOrientationMaskAll; }else if(flagOrientationAll == YES){ return UIInterfaceOrientationMaskAll; } else { return UIInterfaceOrientationMaskPortrait; } } 

在你的视图中实现以下的方式,你要在iPhone和iPod touch上纵向和横向旋转

 -(void)viewWillAppear:(BOOL)animated { self.tabBarController.delegate = self; PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate]; delegate.flagOrientationAll = YES; } } -(void)viewWillDisappear:(BOOL)animated { //NSLog(@"viewWillDisappear -- Start"); PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate]; delegate.flagOrientationAll = NO; } 

也看到这个post: 如何在iphone中设置横向模式的屏幕之一?

您必须在同一视图中创build另一个课程。

在这种情况下,您可以指定自己的方向,只有在您呈现媒体时才会支持横向方向。

我给你一个我的应用程序,它只支持横向模式的例子,但我作为图像select器,它只支持肖像模式,所以我改变了只有该视图的方向。

 #pragma mark - Image PICKER @interface NonRotatingUIImagePickerController : UIImagePickerController @end @implementation NonRotatingUIImagePickerController - (BOOL)shouldAutorotate { return YES; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait ; } @end 

然后当我使用ImagePicker我使用了我所做的类的对象。

所以我定义如下。

 UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init]; 

所以对于图像select器它只显示在肖像模式。

你只需要改变景观,而不是肖像,如果你只想要你想要改变它的特定视图的风景方向。

希望这可以帮助你。