How to force horizontal orientation?

2019-02-15 16:51发布

I want to do the following:

ViewControllerA should not go into horizontal orientation ViewControllerA pushes ViewControllerB ViewControllerB should go into horizontal orientation.

Not sure what to set to make this happen.

2条回答
再贱就再见
2楼-- · 2019-02-15 17:12

Take a look at AlternateViews Apple sample code: it's what you need.

查看更多
太酷不给撩
3楼-- · 2019-02-15 17:19

In each UIViewController, you'll need to override the shouldAutorotateToInterfaceOrientation method and return a boolean value for each interface orientation you support:

// ViewControllerA
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

// ViewControllerB
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

For more information, check out the UIViewController class reference.

查看更多
登录 后发表回答