Force landscape mode in one ViewController using Swift

后端 未结 19 1247
情书的邮戳
情书的邮戳 2020-12-02 07:44

I am trying to force only one view in my application on landscape mode, I am calling

override func shouldAutorotate() -> Bool {
    print(\"shouldAutoro         


        
19条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 07:54

    In ViewController in viewDidLoad Method call below function

    func rotateDevice(){
        UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
        UIView.setAnimationsEnabled(true) // while rotating device it will perform the rotation animation
    }`
    

    App Delegate File Add Below Function & Variables

    //Orientation Variables
    var orientationLock = UIInterfaceOrientationMask.portrait
    var myOrientation: UIInterfaceOrientationMask = .portrait
    
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return .landscape }
    

提交回复
热议问题