lock orientation programmatically in iOS 9

hixhix picture hixhix · Sep 14, 2015 · Viewed 8.3k times · Source

As title, I'm wondering if it's possible to lock orientation programmatically in iOS 9 now? This is critical to my app but I can't find a way to do it. Thanks.

Answer

Oswaldo Leon picture Oswaldo Leon · Nov 25, 2015

Use supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation used to manage orientation for example

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}