我使用了magnometer,但它的值总是不同的。我想要检测当用户设备在横向位置是水平平均值,并且在特定的张贴想要执行一些操作。
发布于 2020-01-18 18:41:39
在didFinishLaunchingWithOptions函数内的AppDelegate.swift中,放入以下代码:
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)然后在AppDelegate中放入以下函数:
func rotated() {
    if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
        print("Landscape")
    }
    if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
        print("Portrait")
    }
}希望它能为您工作... :)
https://stackoverflow.com/questions/59799259
复制相似问题