小编sho*_*eli的帖子

在模态视图之后保持父视图的方向呈现不同的方向

所以我正在开发一个仅支持横向模式的iPad应用程序,除了在一个模态视图控制器上.我遇到的问题是,一旦我呈现模态视图并将方向更改为纵向然后关闭视图,父视图(应该只支持横向)处于纵向模式,直到我旋转设备然后返回到风景和保持这种方式.我一直在努力弄清楚如何让父母保持原始方向,但却未能找到解决方案.

我在我的app委托中有以下代码,只允许在单个模态视图(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;
}
Run Code Online (Sandbox Code Playgroud)

从父类(PhotosViewController)我调用:

GalleryPhotoViewController *gpView = [GalleryPhotoViewController new];
[self presentViewController:gpView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

在我的父(以及其他视图)中,我有以下代码禁止纵向模式:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationPortrait) {
       return YES;
    } else {
        return NO;
    }
}
Run Code Online (Sandbox Code Playgroud)

关于如何在我的父视图上保持方向的任何想法?一旦模态被解除,我在考虑可能只是以编程方式更改viewWillAppear方法中父级的方向,但后来我不知道之前的方向是什么,更不用说我无法找到代码来执行此操作不管是ios6.

编辑/解决方案:所以我找到了一个解决方案,我最终做的是离开应用程序:supportedInterfaceOrientationsForWindow:代码,只是将UINavigation子类添加到呈现模态视图的父视图中,并且所有内容都按预期工作,父级保留其原始在模态能够自由变化的同时取向. …

ipad uiinterfaceorientation modalviewcontroller ios ios6

16
推荐指数
1
解决办法
4730
查看次数

自动旋转在iOS 7中无法正常工作,在iOS 6中运行良好

我有一个应用程序仅支持某些部分(照片库,视频等)的横向方向,并且所有在iOS 6上运行良好没有问题,但是,在iOS 7中应用程序崩溃.

所以继承我的问题:

  1. 使用仅支持肖像的视图控制器启动应用程序并加载初始导航控制器
  2. 将视图控制器推送到支持横向和纵向的堆栈
  3. 将视图旋转到横向
  4. 弹出视图控制器
  5. 应用程序崩溃
-->
CRASH: **preferredInterfaceOrientationForPresentation must return a supported interface orientation!**
2013-11-06 10:18:06.220 ausopen-iphone-2014[57605:70b] Stack Trace: (
  0   CoreFoundation                      0x03f665e4 __exceptionPreprocess + 180
  1   libobjc.A.dylib                     0x03ce38b6 objc_exception_throw + 44
  2   CoreFoundation                      0x03f663bb +[NSException raise:format:] + 139
  3   UIKit                               0x01366f1c -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:]
Run Code Online (Sandbox Code Playgroud)

+ 580

其他信息:

在我的info.plist中,我支持肖像和风景

在我的AppDelegate中,我实现了以下方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{}
Run Code Online (Sandbox Code Playgroud)

在这个方法中,我指定如果第一个视图(HomeVC)显示它应该支持所有方向.

在这个方法中,我还指定如果第二个视图(PhotoVC)显示它也应该支持所有方向.

在我的第一个视图(HomeVC)中,我使用以下方法覆盖此方法,以便在显示视图时仅支持纵向模式:

- (BOOL)shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
} 
Run Code Online (Sandbox Code Playgroud)

不确定iOS …

iphone orientation ios ios6 ios7

7
推荐指数
1
解决办法
8512
查看次数