2010-05-30 136 views
0

我正在使用UIKit製作一個簡單的,傾斜控制的遊戲。到目前爲止,當我傾斜設備時,角色會朝適當的方向移動。我想要他做的是改變我傾斜設備時面臨的方向。例如,當我向左傾斜時,我希望角色朝左。有沒有辦法檢測設備是左傾還是右傾?如果是這樣,請你指點我正確的方向。 謝謝, 泰特iPhone傾斜方向

+2

您是否已經有足夠的信息來做出決定?如果你知道什麼方向移動,你也知道要面對什麼方向。 – 2010-05-30 18:30:22

回答

0

如果知道實際的旋轉是否足夠你。然後,我會建議使用的UIViewController並覆蓋- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation方法

如果你需要更多的東西,那麼我會建議做一個有關加速度計

+0

加速計教程: http://www.switchonthecode.com/tutorials/iphone-tutorial-reading-the-accelerometer UIViewController參考: http://developer.apple.com/iphone/library/documentation/uikit/reference /UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/didRotateFromInterfaceOrientation: – nacho4d 2010-05-30 18:35:24

+0

我需要更多的基於傾斜的控件而不是完整的方向更改,但感謝您的嘗試。 -Tate – 2010-05-30 20:54:58