I am making a simple, tilt controlled game using UIKit. So far, when I tilt the device the character moves in the appropriate direction. What I want him to do is to change the direction he is facing when I tilt the device. For example, when I tilt it left, I want the character to face left. Is there a way to detect whether the device was tilted left or right? If so, could you point me in the right direction please. Thanks, Tate
2 回答
If knowing the actual rotation is good enough for you. Then I would suggest to use an UIViewController and override - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
method
If you need more stuff then I would suggest to do a search about accelerometer
在 John Ray 的名为iOS5 Application Development in 24 Hours的书中,第 18 章说明了使用 CMotionManager 获取加速度计和陀螺仪数据。查看以下网址。您可以下载源代码并加载第 18 章的 ColorTilt 应用程序。它包含有关如何使用陀螺仪信息来确定设备倾斜方向的示例。
http://www.informit.com/store/sams-teach-yourself-ios-5-application-development-in-9780672335761