2014-03-19 5 views
0

저는 Rubymotion에서 장치의 회전을 얻으려고합니다. 이 코드를 viewDidLoad에 추가했습니다.CoreMotion이 rubymotion에서 작동하지 않습니다.

@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에서

답변

0

, 수레 실제로 객체, 그래서 대신 %@를 사용해야합니다 : 당신이 (예를 들어 3 소수점), 별도로 인수를 포맷해야 할 숫자를 포맷하고 싶다면

NSLog "rotation rate = [%@, %@, %@]", motion.rotationRate.x, motion.rotationRate.y, motion.rotationRate.z 

:

NSLog "rotation rate = [%@, %@, %@]", "%.3f" % motion.rotationRate.x, "%.3f" % motion.rotationRate.y, "%.3f" % motion.rotationRate.z 

이 부분은 twitter conversation with one of the RubyMotion developers을 참조하십시오.

+0

오 마이! 나는 오늘 밤 그것을 시도하고 해결 된 것으로 표시 할 것입니다. – Pasta