
import UIKitimport CoreMotionclass VIEwController: UIVIEwController {overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() var motionManager = cmmotionmanager() motionManager.startDeviceMotionUpdates() motionManager.deviceMotionUpdateInterval = 0.1 motionManager.startDeviceMotionUpdatesToQueue( NSOperationQueue.currentQueue()!,withHandler: { (deviceMotion,error) -> VoID in if(error == nil) { self.DeviceMotionUpdate(deviceMotion!) } else { print("error") } })}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning()}func DeviceMotionUpdate(deviceMotion:CMDeviceMotion) { print("function launched") var attitude = deviceMotion.attitude var roll = (attitude.roll) var pitch = (attitude.pitch) var yaw = (attitude.yaw) print("Roll: \(roll),Pitch: \(pitch),Yaw: (yaw)")}} 我没有在startDeviceMotionUpdatesToQueue中得到错误.我在motionManager.deviceMotionActive和motionManager.deviceMotionAvailable上都是如此
解决方法 完成运行vIEwDIDLoad方法后,您的motionManager可能会被销毁.尝试使motionManager成为一个类属性.class VIEwController: UIVIEwController { var motionManager = cmmotionmanager() overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() self.motionManager.startDeviceMotionUpdates() ... 总结 以上是内存溢出为你收集整理的xcode – 运动管理器不工作全部内容,希望文章能够帮你解决xcode – 运动管理器不工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)