2011-01-19 51 views

回答

0

请参阅UIAccelerometer class reference。还有示例代码(请参阅顶部附近的相关示例代码部分)。

+0

Thax DarkDust ...现在我正在理解加速计的魔力。 – 2011-01-19 10:29:43

0

从这个stackoverflow答案

你正在寻找这些API是UIResponder直接复制和粘贴:在UIViewController子类

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { 
    if (event.type == UIEventSubtypeMotionShake) { 
    //Your code here 
    } 
} 

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; 
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event; 
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event; 

一般来说,你只需要实现这个(UIViewController是UIResponder的子类)。另外,你想在motionEnded:withEvent :,而不是motionBegan:withEvent:中处理它。 motionBegan:withEvent:在电话怀疑发生抖动时调用,但操作系统可以确定用户有意晃动和偶然晃动(如走楼梯)之间的差异。如果操作系统在motionBegan:withEvent:被调用后决定它不是真正的摇动,它将调用motionCancelled:而不是motionEnded:withEvent :.

+0

感谢您的建议 – 2011-01-19 10:31:14

1

来自Apple的加速度计参考。这对我真的很有帮助。

相关问题