[英]CoreMotion not working in rubymotion
我正在嘗試使設備在rubymotion中旋轉。 我在viewDidLoad中添加了這段代碼。
@motionManager = CMMotionManager.alloc.init
@motionManager.deviceMotionUpdateInterval = 1.0
if (@motionManager.isDeviceMotionAvailable)
queue = NSOperationQueue.currentQueue
@motionManager.startDeviceMotionUpdatesToQueue(queue, withHandler:lambda do |motion, error|
NSLog "error = %@", error
NSLog "rotation rate = [%f, %f, %f]", motion.rotationRate.x, motion.rotationRate.y, motion.rotationRate.z
end)
else
NSLog "Device Motion is not available: You're likely running this in a simulator"
end
但是它總是記錄以下內容:
rotation rate = [0.000000, 0.000000, 0.000000]
我的工作有什么問題?
在RubyMotion中,浮點數實際上是對象,因此您需要使用%@
代替:
NSLog "rotation rate = [%@, %@, %@]", motion.rotationRate.x, motion.rotationRate.y, motion.rotationRate.z
如果要格式化數字(例如,保留小數點后3位),則需要分別格式化參數:
NSLog "rotation rate = [%@, %@, %@]", "%.3f" % motion.rotationRate.x, "%.3f" % motion.rotationRate.y, "%.3f" % motion.rotationRate.z
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.