iPhone倾斜方向

发布于 2024-09-03 16:35:19 字数 151 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伪心 2024-09-10 16:35:20

如果知道实际的旋转对您来说就足够了。然后我建议使用 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 method

If you need more stuff then I would suggest to do a search about accelerometer

神爱温柔 2024-09-10 16:35:20

在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文