how to change a view from portrait mode to landscape mode and lock it?

后端 未结 1 1125
余生分开走
余生分开走 2021-01-17 02:25

I have a movie view compressed at the right-bottom viewport with portrait mode. And the movie view will expand to full screen in landscape mode when user expand the movie vi

相关标签:
1条回答
  • 2021-01-17 03:07

    It's caused by this function,

    func application(_ application: UIApplication,
                     supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return shouldRotate ? .allButUpsideDown : .portrait
    }
    

    change .allButUpsideDown to .landscape will do.

    workable code,

    AppDelegate.swift

    func application(_ application: UIApplication,
                     supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return shouldRotate ? .landscape : .portrait
    }
    

    view controller,

    func expandPlayerWindow() {
        self.player.view.frame = CGRect(x:0, y:-20, width: UIScreen.main.bounds.maxY, height: UIScreen.main.bounds.maxX)
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.shouldRotate = true // or false to disable rotation
        let value = UIInterfaceOrientation.landscapeLeft.rawValue
        UIDevice.current.setValue(value, forKey: "orientation")
        appDelegate.shouldRotate = true
        UIApplication.shared.isStatusBarHidden = true
    }
    
    0 讨论(0)
提交回复
热议问题