[英]App can auto rotate to landscape from portrait on iPad but not on iPhone
我想使ViewController A为人像,而ViewController B为风景。 当它运行时,即使我将应用程序委托设置为横向,一切都会变成纵向。 您能告诉我要怎么做吗? 以下是我的工作..
ViewController A将要查看控制器B:
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = TRUE;
MapViewController * sliderVC = [[MapViewController alloc] init ];
sliderVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:sliderVC animated:NO completion:nil];
sliderVC.view.backgroundColor = [UIColor clearColor];
AppDelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation)//set the bool value to view controller which you want to load in landscape
return UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
确保您支持所需的方向:
项目>目标>常规
您应在View Controller B上重写以下方法:
func shouldAutorotate() -> Bool
func supportedInterfaceOrientations() -> Int
func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation
您在AppDelegate中覆盖的方法适用于整个应用程序。
我建议您看一下相关文档。
基本上,这是所有视图控制器需要执行的操作:
#pragma mark Orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.