iPhone開発メモ シェイク

このエントリをはてなブックマークに追加

OS3.0から簡単にシェイク機能を実装出来るようになったらしい。
UIResponderのmotionEndedを実装すればいい。

- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
	if (event.type == UIEventTypeMotion &&	motion == UIEventSubtypeMotionShake) {
                // ここにシェイク時のプログラムを書く
		if ([shakeDelegate respondsToSelector:@selector(ShakeExec)]) {
			[self dismissWithClickedButtonIndex:self.cancelButtonIndex animated:YES];
			[shakeDelegate ShakeExec];
		}
	}
}

でも、なんか動かない端末があるっぽい・・・OSは3.0以上なんだけどなんでだろう!?
どうも、ファーストレンポンダーとかってのにならなきゃダメのようだ。
なので下記のコードを追加。

- (BOOL) canBecomeFirstResponder {
	return YES;
}

後は、viewDidLoadとかで [self becomeFirstResponder]; を呼べばOK!
今度はどうだろうか・・・

What I'm Doing...

Posting tweet...

Powered by Twitter Tools

Get Adobe Flash playerPlugin by wpburn.com wordpress themes