强制 UIViewController 处于横向模式 iOS7 [英] force UIViewController to be in Landscape mode iOS7
问题描述
我已经实现了正确的功能,但它们没有被触发?我在 StackOverFlow 上尝试了几种解决方案,但都没有奏效.我试过将视图添加到 UINavigationController,也不起作用.
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.
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;
}
推荐答案
如果您将视图控制器推送到导航控制器中其他视图控制器的堆栈,则仅需要横向将无法正常工作.您应该以模态方式显示横向约束视图控制器.
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.
在此处查看我的答案以获取示例项目:https://stackoverflow.com/a/16022631/983912
See my answer here for an example project: https://stackoverflow.com/a/16022631/983912
这篇关于强制 UIViewController 处于横向模式 iOS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!