2011-01-19 33 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的加速度計參考。這對我真的很有幫助。

相關問題