2008-11-12touch系 #2

お金を払えば touch できるお店があるんですよね。
嫌いじゃないです…と、開発 blog に書く事ではないのです。
で、件の touch 系ですが、実験しててわかりました。
つか、ドキュメントをちゃんと読めば載っている事なのかもしれないが…
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self];
やらで touch 系オブジェクト&プロパティを取得できるんですが、コレには
ちょっとした罠がありましてー
右や左にスライドさせた時、タップ(1クリック)した時の取得は前回書きましたが、
この"タップ(1クリック)" って判断を touchBegan でやってしまうと良くない。
あくまでも、touchesEnded で完結させねばならない。
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self]; if ([touch tapCount] == 1) { //1回タップの処理いろいろ … } // 右にスライドの処理うんぬん if (pointX < location.x - 30) { [mesArray removeObjectAtIndex:0]; [mesArray addObject:@"glided 2 the right ->"]; … まぁ色々書く }
こんなふうに(絵描きのボブ風)
スライドとして判断したい時も、 touchBegan で if ([touch tapCount] == 1) { やっちまうと
touchCount が 1 となり、 タップの処理が走り touchEnded でもスライドの処理をしてしまう。
2重に処理しちまうので区別ができない。
だから、touch 系の判断処理は全て touch Ended で!
touchBegan では初期位置を取得するだけで! - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self]; pointX = location.x; pointY = location.y; // もうコレだけでいいや! }
ね、簡単でしょ?(絵描きのボブ風)
簡単だよ、ドキュメント読めよ>自分
と、何度思っても読まないんですよね。うへへへへ
まぁ touchEnded だけでも後々問題が出そうではあるんだけど…
VB だかの mouseDown mouseUp でハマった事を思い出しました。
コメントを書く