【问题标题】:Portrait orientation in all view controllers except in modal view controller除模态视图控制器外,所有视图控制器中的纵向
【发布时间】:2013-02-26 20:27:48
【问题描述】:

我正在展示带有代码的模态视图:

 [self presentViewController:movieViewController animated:YES completion:^{
     // completed
 }];

在movieViewController中,控制器被解除:

[self dismissViewControllerAnimated:YES completion:^{
    // back to previous view controller
}];

目前,我所有的视图控制器都可以纵向和两个横向查看。

除了模态视图控制器外,我如何将所有视图控制器限制为纵向?所以模态视图控制器可以在三个方向上看到,其他一切都在一个方向上。

【问题讨论】:

  • 你要使用 iOS 6 还是 5?

标签: ios objective-c uiviewcontroller uiinterfaceorientation


【解决方案1】:

在 appDelegate 中:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }

带有方法的特殊 UINavigationController 子类(如果您使用导航控制器):

- (NSUInteger)supportedInterfaceOrientations {
    if (self.topViewController.presentedViewController) {
        return self.topViewController.presentedViewController.supportedInterfaceOrientations;
    }
    return self.topViewController.supportedInterfaceOrientations;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.topViewController.preferredInterfaceOrientationForPresentation;
}

每个视图控制器都应该返回它自己支持的方向和首选的呈现方向:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

我的应用以纵向模式运行,但视频播放器以模态 vc 形式打开:

 - (NSUInteger)supportedInterfaceOrientations {
     return UIInterfaceOrientationMaskAllButUpsideDown;
 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
     return UIInterfaceOrientationLandscapeLeft;
 }

它非常适合我,希望对我有帮助!

【讨论】:

  • 我不得不在我的视频播放器的supportedInterfaceOrientations 中使用UIInterfaceOrientationMaskLandscapeLeft 强制横向才能使其正常工作。否则我会崩溃。但是视频是横向观看的,没有问题。
  • 不,您需要将所有支持的方向作为掩码返回,并返回横向方向之一作为演示的首选。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
  • 1970-01-01
  • 2014-10-13
  • 1970-01-01
  • 2013-05-18
相关资源
最近更新 更多