How to set certain view controller to be landscape and portrait and certain to be landscape only ? (iOS)

我只是一个虾纸丫 提交于 2019-12-11 11:07:00

问题


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


回答1:


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/




回答2:


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;

}


来源:https://stackoverflow.com/questions/37085341/how-to-set-certain-view-controller-to-be-landscape-and-portrait-and-certain-to-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!