如何在 iPhone SDK 3.0 中使用 Shake API? [英] How to use Shake API in iPhone SDK 3.0?

查看:24
本文介绍了如何在 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.

推荐答案

您正在寻找的 API 位于 UIResponder:

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
  }
}

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

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

这篇关于如何在 iPhone SDK 3.0 中使用 Shake API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆