在iPhone SDK上实现摇动/滑动功能

发布于 2024-09-10 09:19:38 字数 146 浏览 5 评论 0原文

我想制作一个像“10,500 个很酷的事实”这样的应用程序,

基本上,背景上有一些文本,然后用户会摇晃或向右/向左滑动以在不同的事实之间导航。

我是 iPhone 编程/SDK 的新手,所以想知道是否有人可以帮助我开始。 如何实现摇动/滑动功能?

I want to make an app like "10,500 cool facts"

Basically, there is some text on background, and then the user will shake, or slide right/left to navigate between the different facts.

I am new to iPhone programming/SDK, so wondering if anyone could help me get started.
How do I implement a shake / slide function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

赠意 2024-09-17 09:19:38

首先,我强烈建议您在想要使用摇动手势进行任何操作时要小心,特别是如果您是 iOS 编程新手。当第一个应用程序出现时,它风靡一时,直到人们开始意识到摇动几乎可以用于任何事情,使其成为一个毫无意义的功能。由于缺乏更好的术语,它已经成为过去。

如果您致力于摇动手势,则需要子类化 UIWindow 并实现以下方法:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent*)event;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent*)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent*)event;

您要查找的 UIEventSubtypeUIEventSubtypeMotionShake< /代码>。

至于你的“幻灯片”功能,我假设你基本上是在谈论屏幕之间的水平分页。有很多方法可以做到这一点,我认为这将归结为如何实现底层视图控制器层次结构。我自己没有这样做过,但如果是的话,我可能只是手动检测用户对我的视图的触摸,以确定是否有人从左到右或从右到左滑动,然后使用匹配的过渡更改视图动画片。

First, I urge caution when wanting to use a shake gesture for anything, especially if you are new to iOS programming. It was all the rage when the first apps started coming out, until people started realizing that shaking was being used for just about anything, making it mostly a meaningless feature. It's become, for the lack of a better term, passe.

If you're committed to the shake gesture, you'll want to subclass UIWindow and implement the following methods:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent*)event;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent*)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent*)event;

The UIEventSubtype you're looking for is UIEventSubtypeMotionShake.

As for your "slide" function, I assume you're basically talking about paging between screens horizontally. There are a number of ways you can do this, and I think it will boil down to how you're implementing your underlying view controller hierarchy. I haven't done it myself, but if I were, I'd probably just manually detect user touches on my view to determine if someone's swiping left-to-right or right-to-left, and then change views with a matching transition animation.

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