Getting device orientation in Swift

后端 未结 13 1464
滥情空心
滥情空心 2020-11-28 23:23

I was wondering how I can get the current device orientation in Swift? I know there are examples for Objective-C, however I haven\'t been able to get it working in Swift.

13条回答
  •  旧时难觅i
    2020-11-28 23:43

    Swift 4:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
            if UIDevice.current.orientation.isLandscape {
                print("landscape")
            } else {
                print("portrait")
            }
        }
    

提交回复
热议问题