2013-02-26 123 views
4

我提出一个模式的看法与代码:纵向方向除了在模式视图控制器

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

内movieViewController,控制器被驳回用:

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

在那时,我所有的视图控制器都可以以纵向和两种风景方向进行查看。

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

+0

你打算使用iOS 6还是5? – iiFreeman 2013-02-26 22:25:19

+0

iOS 6及以上 – cannyboy 2013-02-27 00:40:29

回答

20

在的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; 
} 

它适合我,希望它有帮助!

+0

我不得不在我的视频播放器的supportedInterfaceOrientations UIInterfaceOrientationMaskLandscapeLeft强制景观,以使其工作。否则我会得到崩溃。但视频是为了观看风景,不是没有probs。 – cannyboy 2013-02-27 17:55:55

+0

不,您需要将所有支持的方向作为蒙版返回,并返回一个横向方向作为演示文稿的首选方向。 – iiFreeman 2013-02-27 19:47:45

+0

爱你! :)效果很好 – 2014-01-31 08:50:16

相关问题