如何在iPhone SDK 3.0中使用Shake API?

发布于 2024-07-29 02:31:29 字数 99 浏览 4 评论 0原文

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 技术交流群。

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

发布评论

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

评论(3

一杯敬自由 2024-08-05 02:31:30

您要查找的 API 位于 UIResponder

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

通常你只需在你的 UIViewController 子类中实现这个

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
  if (event.type == UIEventSubtypeMotionShake) {
    //Your code here
  }
}

(UIViewController 是 UIResponder 的子类)。 另外,您希望在motionEnded:withEvent:中处理它,而不是motionBegan:withEvent:。 motionBegan:withEvent: 当手机怀疑正在发生晃动时调用,但操作系统可以确定用户故意晃动和偶然晃动(例如走上楼梯)之间的区别。 如果操作系统在调用motionBegan:withEvent:后认为这不是真正的震动,它将调用motionCancelled:而不是motionEnded:withEvent:。

The APIs you are looking for are in UIResponder:

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

Generally you just implement this:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
  if (event.type == UIEventSubtypeMotionShake) {
    //Your code here
  }
}

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:.

放血 2024-08-05 02:31:30

我在此线程中发布了完整的 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?

眼趣 2024-08-05 02:31:30

Joe Hewitt 最近提交一些代码到Three20 利用 3.0 摇动事件。 似乎您只需要在 -motionBegan:withEvent: 在您的 UIResponder

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.type == UIEventSubtypeMotionShake) {
        ...
    }
}

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 your UIResponder.

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.type == UIEventSubtypeMotionShake) {
        ...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文