How to force view controller orientation in iOS 8?

前端 未结 25 2567
太阳男子
太阳男子 2020-11-22 13:11

Before iOS 8, we used below code in conjunction with supportedInterfaceOrientations and shouldAutoRotate delegate methods to force app orie

25条回答
  •  甜味超标
    2020-11-22 13:20

    For iOS 7 - 10:

    Objective-C:

    [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@"orientation"];
    [UINavigationController attemptRotationToDeviceOrientation];
    

    Swift 3:

    let value = UIInterfaceOrientation.landscapeLeft.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")
    UINavigationController.attemptRotationToDeviceOrientation()
    

    Just call it in - viewDidAppear: of the presented view controller.

提交回复
热议问题