iPhone倾斜方向
我正在使用 UIKit 制作一个简单的倾斜控制游戏。到目前为止,当我倾斜设备时,角色会朝适当的方向移动。我希望他做的是当我倾斜设备时改变他所面对的方向。例如,当我向左倾斜时,我希望角色面向左侧。有没有办法检测设备是否向左或向右倾斜?如果是这样,请您给我指出正确的方向。 谢谢, 泰特美术馆
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果知道实际的旋转对您来说就足够了。然后我建议使用 UIViewController 并重写
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
方法如果您需要更多东西,那么我建议搜索有关加速度计的内容
If knowing the actual rotation is good enough for you. Then I would suggest to use an UIViewController and override
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
methodIf you need more stuff then I would suggest to do a search about accelerometer
在 John Ray 的书《24 小时内进行 iOS5 应用程序开发》中,第 18 章说明了如何使用 CMotionManager 来获取加速度计和陀螺仪数据。查看以下网址。您可以下载源代码并加载第 18 章的 ColorTilt 应用程序。它包含如何使用陀螺仪信息来确定设备倾斜方向的示例。
http://www.informit.com /store/sams-teach-yourself-ios-5-application-development-in-9780672335761
In John Ray's book titled iOS5 Application Development in 24 Hours, chapter 18 illustrates using the CMotionManager to get accelerometer and gyroscope data. Check out the following URL. You can download the source code and load up Chapter 18's ColorTilt application. It contains examples of how to use the gyroscopic information to determine which direction the device was tilted.
http://www.informit.com/store/sams-teach-yourself-ios-5-application-development-in-9780672335761