iOS获取面朝上方向的角度
当加载面向上的屏幕时,我需要知道iPhone的角度 iPhone平放在桌子上,但我只需要知道它是垂直还是水平位置iOS获取面朝上方向的角度,ios,objective-c,uideviceorientation,Ios,Objective C,Uideviceorientation,当加载面向上的屏幕时,我需要知道iPhone的角度 iPhone平放在桌子上,但我只需要知道它是垂直还是水平位置 我不能使用StatusBaroOrientation,因为我有固定的方向。状态栏的方向始终相同这可能是使用CoreMotion的好时机。看起来阅读CoreMotionRate可以满足您的需求: 从文档中: /* * CMRotationRate * * Discussion: * A structure containing 3-axis rotation ra
我不能使用StatusBaroOrientation,因为我有固定的方向。状态栏的方向始终相同这可能是使用CoreMotion的好时机。看起来阅读CoreMotionRate可以满足您的需求: 从文档中:
/*
* CMRotationRate
*
* Discussion:
* A structure containing 3-axis rotation rate data.
*
* Fields:
* x:
* X-axis rotation rate in radians/second. The sign follows the right hand
* rule (i.e. if the right hand is wrapped around the X axis such that the
* tip of the thumb points toward positive X, a positive rotation is one
* toward the tips of the other 4 fingers).
* y:
* Y-axis rotation rate in radians/second. The sign follows the right hand
* rule (i.e. if the right hand is wrapped around the Y axis such that the
* tip of the thumb points toward positive Y, a positive rotation is one
* toward the tips of the other 4 fingers).
* z:
* Z-axis rotation rate in radians/second. The sign follows the right hand
* rule (i.e. if the right hand is wrapped around the Z axis such that the
* tip of the thumb points toward positive Z, a positive rotation is one
* toward the tips of the other 4 fingers).
*/
如何获取这些值的快速示例:
private lazy var motionManager: CMMotionManager = {
return CMMotionManager()
}()
func recordMotion() {
motionManager.startDeviceMotionUpdatesToQueue(opQueue, withHandler: { (deviceMotion, error) in
if let motion = deviceMotion {
print(motion.rotationRate.x)
print(motion.rotationRate.y)
print(motion.rotationRate.z)
}
})
}
你是指纵向还是横向?或者您指的是加速计?设备方向是朝上方向。我指的是手机的加速度计旋转。里士满的解决方案对我有效!谢谢,太好了!这正是我需要的!