本文介绍了iOS 7:如何仅允许VC的纵向方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的所有项目都允许以横向/纵向模式查看应用程序,但对于一个View Controller,我想禁用此功能并仅以纵向显示它。
All my project allow to view app in landscape/portrait mode, but for one View Controller I want to disable this function and show it only in portrait orientation.
我试过 shouldAutorotate
和 supportedInterfaceOrientations
,但它不起作用。
I have tried shouldAutorotate
and supportedInterfaceOrientations
, but it don't work.
推荐答案
如果您想要视图控制器的不同方向,请在 AppDelegate
中添加此方法 -
If you want different orientation for view controllers, In AppDelegate
add this method -
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;
if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}
return orientations;
}
和你的ViewController -
and in your ViewController -
-(BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return (UIInterfaceOrientationMaskAll);//Change this according to your need
}
希望这会有所帮助。
这篇关于iOS 7:如何仅允许VC的纵向方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!