如何在iPhone SDK 3.0中使用Shake API?
Apple 在 iPhone SDK 3.0 中发布了 Shake API。 我找不到有关此新功能的任何信息。
谁知道如何使用它? 任何例子,链接都会很好。
Apple annonced Shake API in iPhone SDK 3.0. I can not find any information regarding this new feature.
Who knows about how to use it? Any example, link will be good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要查找的 API 位于 UIResponder:
通常你只需在你的 UIViewController 子类中实现这个
(UIViewController 是 UIResponder 的子类)。 另外,您希望在motionEnded:withEvent:中处理它,而不是motionBegan:withEvent:。 motionBegan:withEvent: 当手机怀疑正在发生晃动时调用,但操作系统可以确定用户故意晃动和偶然晃动(例如走上楼梯)之间的区别。 如果操作系统在调用motionBegan:withEvent:后认为这不是真正的震动,它将调用motionCancelled:而不是motionEnded:withEvent:。
The APIs you are looking for are in UIResponder:
Generally you just implement this:
in your UIViewController subclass (UIViewController is a subclass of UIResponder). Also, you want to handle it in motionEnded:withEvent:, not motionBegan:withEvent:. motionBegan:withEvent: is called when the phone suspects shaking is happening, but the OS can determine the difference between a user purposefully shaking, and incidental shaking (like walking up the stairs). If the OS decides it was not a real shake after motionBegan:withEvent: is called it will call motionCancelled: instead of motionEnded:withEvent:.
我在此线程中发布了完整的 3.0 示例:
How do I detector当有人摇晃 iPhone 时?
I posted a complete 3.0 example in this thread:
How do I detect when someone shakes an iPhone?
Joe Hewitt 最近提交一些代码到Three20 利用 3.0 摇动事件。 似乎您只需要在
-motionBegan:withEvent:
在您的UIResponder
。Joe Hewitt recently committed some code to Three20 that utilizes the 3.0 shake event. Seems like you just need to implement some simple code within
-motionBegan:withEvent:
inside of yourUIResponder
.