import UIKit
import CoreMotion
class ViewController: UIViewController {
var motionManager = CMMotionManager()
@IBOutlet weak var directionLb: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
motionManager.startDeviceMotionUpdates(using: CMAttitudeReferenceFrame.xTrueNorthZVertical, to: OperationQueue.main) {
(motion, error) in
let yaw = motion!.attitude.yaw
let yawDegrees = yaw * 180 / Double.pi
self.directionLb.text = String(format: "Direction:%0.2f", yawDegrees);
}
}
}
获取罗盘方向
最新推荐文章于 2022-07-08 10:16:06 发布