我有一个始终以纵向模式显示的应用程序.
但在某个地方,我有一个必须支持景观的媒体画廊.
默认情况下,项目中支持的方向是纵向.因此,画廊仅以肖像模式显示.
如果我将项目设置更改为以纵向和横向显示,则图库工作正常,但我无法控制其他viewControllers仅以纵向显示.
我尝试了几种方法,如shouldAutoRotate,但没有人工作.
任何ideia怎么解决?
问候
编辑:
解决了 :)
首先,我配置项目以支持所有方向.
然后我将此方法添加到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;
- (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设备中以纵向和横向旋转
-(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; }
看这篇文章也是:How to set one of the screens in landscape mode in iphone?