How to set certain view controller to be landscape

2019-08-12 13:29发布

How can I set certain view controller to be landscape and portrait and certain to be landscape only? Thanks .

2条回答
男人必须洒脱
2楼-- · 2019-08-12 13:46

Step 1. Create a subclass of UINavigationcontroller named like CustomNavController Step 2. initialise CustomNavController instead of UINavigationController in AppdDelegate.

Step 3. override following method of UINavigationController in CustomNavController

-(NSUInteger) supportedInterfaceOrientations
{

    if([NSStringFromClass([[[self viewControllers] lastObject] class]) isEqualToString:@"ViewAsset"]){
        return UIInterfaceOrientationMaskAll;
    }

    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

where ViewAsset is name of class which you need in both mode.

for more interesting tutorials check out https://appengineer.in/

查看更多
女痞
3楼-- · 2019-08-12 13:54

1) Select the "device orientations" that you want in your project from the "Deployment Info" in the "General" tab.

2) In your view controller class, use this code:

- (UIInterfaceOrientationMask) supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskPortrait;

}

3) For view controllers that you want to support both orientations:

- (UIInterfaceOrientationMask) supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;

}
查看更多
登录 后发表回答