Getting device orientation in Swift

后端 未结 13 1460
滥情空心
滥情空心 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条回答
  •  悲&欢浪女
    2020-11-28 23:39

       override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
        if (toInterfaceOrientation.isLandscape) {
            NSLog("Landscape");
        }
        else {
            NSLog("Portrait");
        }
    }
    

提交回复
热议问题