タップ数でダイレクトにセレクトしたい…
タップ数で機能を選択でできねぇ~?
ってのたまわれた…。
タップ1回(もしくはタッチ)ならマップ移動で…
タップ2回ならショットで…
タップ3回なら…。
…etc…
…
どうしたら良いのかね?
途中、ショットとか手を放したら処理として成立するものがあると
上手くいかない…。
最終的に『何回タップしました』って形に結果が来ないと困る…。
取り合えずアップルのヘルプをチョコチョコっと見てみた…。
タップ処理でレスポンダオブジェクトってのは難しいそうだ…
うんぬんかんぬんぐらいしか書いていない…。
もうチョット詳しく書いて欲しいぞ!
…
サンプルによるとタップしたらスレッドを作って
次のタップが来るかもしれない時間を待つ。
タップが来たら前のスレッドを削除し、そして新しい待ちスレッドを立てる。
タップが来なかったらそのスレッドの処理を行う方法。
でもダブルタップのディレイって幾つなんかね?
探しても見付からないんですけど…。
設定項目も無さそうなので固定値かと思われるのだが…
なんかの関数で得られるのかね?
…
こっちに結構良いサンプルを見付けた。
ちなみに本のサンプルにも似たようなものがあったよ。
これを細工して幾らでもタップカウントが出来るようにしてみた…。
『View-base Application』でプロジェクトを作って…
[TapsViewController.h]
//--------------------------------------
- ( void )touchesBegan:( NSSet* )touches withEvent:( UIEvent* )event;
- ( void )touchesMoved:( NSSet* )touches withEvent:( UIEvent* )event;
- ( void )touchesEnded:( NSSet* )touches withEvent:( UIEvent* )event;
- ( void )touchesCancelled:( NSSet* )touches withEvent:( UIEvent* )event;
[TapsViewController.m]
//******************************************************************************
// タッチ処理
//******************************************************************************
//**************************************
// Work
//**************************************
#define TAP_INTERVAL 0.5
//--------------------------------------
BOOL touchStartFlag; // タッチフラグ
BOOL touchFlag; // タッチフラグ
int touchTaps; // タップ回数
CGPoint touchPoint; // タッチ位置
CGPoint touchMove; // タッチ移動量
//**************************************
// touchInfo
//**************************************
- ( void ) touchInfo
{
char string[512];
int t, m;
float x, y;
if( !touchFlag )
{
t = 0;
x = 0;
y = 0;
} else
{
t = touchTaps;
x = touchMove.x;
y = touchMove.y;
}
m = touchStartFlag;
sprintf( string, "taps:%2d\nmx:%f\nmy:%f\nmode:%d", t, x, y, m );
[infoTextView setText:[NSString stringWithUTF8String:string] ];
}
//**************************************
// touchesParameterGet
//**************************************
- ( void ) touchesParameterGet:( NSSet* )touches
{
static CGPoint pointBackup;
UITouch *touch = [touches anyObject];
touchPoint = [touch locationInView:self.view];
switch( touch.phase )
{
case UITouchPhaseBegan:
touchStartFlag = TRUE;
pointBackup = touchPoint;
// …何か処理…
break;
case UITouchPhaseEnded:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector( touchTapMethod ) object:nil];
touchFlag = FALSE;
touchStartFlag = FALSE;
// …何か処理…
break;
default:
if( !touchFlag )
return;
break;
case UITouchPhaseCancelled:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector( touchTapMethod ) object:nil];
touchFlag = FALSE;
touchStartFlag = FALSE;
return;
}
touchMove.x = touchPoint.x - pointBackup.x;
touchMove.y = -touchPoint.y + pointBackup.y;
// …何か処理…
[self touchInfo];
}
//**************************************
//
//**************************************
- ( void ) touchTapMethod
{
touchFlag = TRUE;
[self touchInfo];
}
//**************************************
// touchesBegan
//**************************************
- ( void )touchesBegan:( NSSet* )touches withEvent:( UIEvent* )event
{
UITouch *touch = [touches anyObject];
touchTaps = [touch tapCount];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector( touchTapMethod ) object:nil];
[self performSelector:@selector( touchTapMethod ) withObject:nil afterDelay:TAP_INTERVAL];
[self touchesParameterGet:touches];
}
//**************************************
// touchesMoved
//**************************************
- ( void ) touchesMoved:( NSSet* )touches withEvent:( UIEvent* )event
{
[self touchesParameterGet:touches];
}
//**************************************
// touchesEnded
//**************************************
- ( void ) touchesEnded:( NSSet* )touches withEvent:( UIEvent* )event
{
[self touchesParameterGet:touches];
}
//**************************************
// touchesCancelled
// ※電話の着信などの強制割り込み時に呼ばれます。
//**************************************
- ( void ) touchesCancelled:( NSSet* )touches withEvent:( UIEvent* )event;
{
[self touchesParameterGet:touches];
}
//******************************************************************************
// End
//******************************************************************************
分かりきっていると思うけどレスポンスは、悪くなる。
なので入力状態がユーザーに分かるようにする表示の工夫か
もしくは、0.5秒間タッチさせたくなる演出上の工夫が必要かもしれない。
例えば、タップすると『1タップ・2タップ』などタップ数に合わせて
吹き出しをズームさせて注視させるなどが考えられる。
ズームに0.4秒使えばタップ待ちが気にならないのでは?
タップするたびに項目が浮かび上がるでも良いんじゃないだろうか?
まあ、処理の一つとして用意しておくと何かの時に助かるかも…。
って訳でメモ、メモ♪
PS.
自分が困った時用にサンプルもアップしておこう…。(笑)
| 固定リンク
コメント