所以我正在开发一个只支持横向模式的iPad应用程序,除了在一个模态视图控制器上.我遇到的问题是,一旦我提出模态视图,并将方向改变为纵向,然后关闭视图,父视图(只应支持横向)是纵向模式,直到我旋转设备,然后再回到景观和住宿方式.我一直在努力弄清楚如何让父母看到原始的方向,但是却无法找到解决方案.
我的应用程序委托中有以下代码,仅允许在单个模态视图(GalleryPhotoViewer)上进行方向更改:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown; if(self.window.rootViewController){ UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; //Support Portrait mode only on Photoviewer if ([[presentedViewController presentedViewController] isKindOfClass:GalleryPhotoViewController.class] ) { orientations = UIInterfaceOrientationMaskAll; }else{ orientations = [presentedViewController supportedInterfaceOrientations]; } } return orientations; }
从父类(PhotosViewController)我打电话:
GalleryPhotoViewController *gpView = [GalleryPhotoViewController new]; [self presentViewController:gpView animated:YES completion:nil];
还有在我的父母(和其他意见)我有以下代码不允许肖像模式:
- (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationPortrait) { return YES; } else { return NO; } }
关于我如何保持我父母观点的方向的任何想法?我正在考虑可能只是以编程方式在viewWillAppear方法中改变方向,一旦模态被关闭,然后我不知道以前的方向是什么,更不用说我还没有找到代码来做这个不管ios6.
编辑/解决方案:所以我找到一个解决方案,我最后做的是离开应用程序:supportedInterfaceOrientationsForWindow:代码,只是将UINavigation子类添加到父视图,呈现模态视图,一切按预期工作,父级保留原来而模态能够自由地改变.
在我的父母:
//To make sure that this view remains in Landscape @implementation UINavigationController (Rotation_IOS6) -(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } @end
感谢@matt的建议.
解决方法
我认为问题是你使用的应用程序:supportedInterfaceOrientationsForWindow :.相反,摆脱这一点,并从UINavigationController子类开始,并将根视图控制器的类作为您的导航界面.然后:
>在UINavigationController子类中,从supportedInterfaceOrientations返回UIInterfaceOrientationMaskLandscape.>在显示(模态)视图控制器中,从supportedInterfaceOrientations返回UIInterfaceOrientationMaskAll.