AppleはiPhoneSDK3.0でShakeAPIを発表しました。この新機能に関する情報が見つかりません。
誰がそれを使用する方法を知っていますか?どんな例でも、リンクは良いでしょう。
AppleはiPhoneSDK3.0でShakeAPIを発表しました。この新機能に関する情報が見つかりません。
誰がそれを使用する方法を知っていますか?どんな例でも、リンクは良いでしょう。
探しているAPIはUIResponderにあります:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;
通常、これを実装するだけです。
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
//Your code here
}
}
UIViewControllerサブクラス内(UIViewControllerはUIResponderのサブクラスです)。また、motionBegan:withEvent:ではなく、motionEnded:withEvent:で処理する必要があります。motionBegan:withEvent:は、電話が揺れが発生している疑いがある場合に呼び出されますが、OSは、ユーザーが意図的に揺れているのか、偶発的に揺れているのか(階段を上るなど)の違いを判断できます。OSが、motionBegan:withEvent:が呼び出された後、実際のシェイクではないと判断した場合、motionEnded:withEvent:の代わりにmotionCancelled:を呼び出します。
私はこのスレッドで完全な3.0の例を投稿しました:
Joe Hewittは最近、3.0シェイクイベントを利用するコードをThree20にコミットしました。内にいくつかの簡単なコードを実装する必要があるようです。-motionBegan:withEvent:
UIResponder
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
...
}
}