xcode 强制 UIViewController 处于横向模式 iOS7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21615848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:38:04  来源:igfitidea点击:

force UIViewController to be in Landscape mode iOS7

objective-cxcodeuiviewcontrollerorientation

提问by Jim Clermonts

I've implemented the proper functions, but they don't get triggered? I've tried several solutions here on StackOverFlow, but none of them work. I've tried adding the view to a UINavigationController, also doesn't work.

我已经实现了正确的功能,但它们没有被触发?我在 StackOverFlow 上尝试了几种解决方案,但都没有奏效。我试过将视图添加到 UINavigationController,也不起作用。

FakeIDDetailViewController.h:

FakeIDDetailViewController.h:

@interface FakeIDDetailViewController : UIViewController
@end

FakeIDDetailViewController.m:

FakeIDDetailViewController.m:

@interface FakeIDDetailViewController ()

-(BOOL)shouldAutorotate
{
    return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (UIInterfaceOrientationMaskLandscapeLeft);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

- (NSUInteger) application:(UIApplication *)application     supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationLandscapeLeft;
}

回答by Leo Natan

If you are pushing a view controller to a stack of other view controllers in a navigation controller, requiring landscape only will not work well. You should display the landscape-constraint view controller modally.

如果您将视图控制器推送到导航控制器中的其他视图控制器堆栈,则仅需要横向将无法正常工作。您应该以模态方式显示横向约束视图控制器。

See my answer here for an example project: https://stackoverflow.com/a/16022631/983912

有关示例项目,请在此处查看我的答案:https: //stackoverflow.com/a/16022631/983912

回答by matt

For a navigation controller interface, forcing an orientation is not supported by the framework. See my answer here: https://stackoverflow.com/a/15301322/341994

对于导航控制器界面,框架不支持强制方向。在此处查看我的答案:https: //stackoverflow.com/a/15301322/341994

For a workaround (not very good), see my answer here: https://stackoverflow.com/a/16379515/341994

有关解决方法(不是很好),请在此处查看我的答案:https: //stackoverflow.com/a/16379515/341994

However, forcing an orientation works fine for a presented view controller.

但是,强制方向对于呈现的视图控制器来说效果很好。