应用程序可以自动旋转到iPad上的纵向横向,但不能在iPhone上旋转

时间:2015-07-07 11:16:03

标签: ios objective-c iphone ipad screen-orientation

我想使ViewController成为一个肖像和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;
}

3 个答案:

答案 0 :(得分:1)

确保您支持所需的方向:

项目>目标>一般

enter image description here

答案 1 :(得分:0)

您应该在View Controller B上覆盖以下方法:

func shouldAutorotate() -> Bool
func supportedInterfaceOrientations() -> Int
func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation

您在AppDelegate中覆盖的方法适用于整个应用。

Reference

答案 2 :(得分:0)

我建议您查看相关文档。

Multiple Orientations

基本上这是你需要为所有视图控制器做的事情:

#pragma mark Orientation handling

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}