我试图在Monotouch中使用加速度计,但是MotionManager有问题。更新将在2-3秒后停止发送。
这是密码。(所有内容都是在主UIView的构造函数中创建的)。
CMMotionManager motionManager = new CMMotionManager();
motionManager.AccelerometerUpdateInterval = 0.5;
motionManager
.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue,
delegate(CMAccelerometerData data, NSError error)
{
myLabel.Text = data.Acceleration.X.ToString("0.0000");
});在UIAccelerometer中,它正在工作:
UIAccelerometer acc = UIAccelerometer.SharedAccelerometer;
acc.UpdateInterval = 0.5;
acc.Acceleration += delegate(object sender, UIAccelerometerEventArgs e)
{
myLabel.Text = e.Acceleration.X.ToString("0.0000");
};有什么想法吗?
发布于 2013-01-28 17:07:39
没有足够的源代码来查看是否保留对CMMotionManager实例的引用。否则GC可以释放它,这将停止任何更新。
相比之下,您使用的是共享 UIAccelerometer (它永远不会被GC‘’ed),而您正在创建自己的CMMotionManager (可能是这样)。
https://stackoverflow.com/questions/14567187
复制相似问题