4

ボタンを1回クリックするか、クリックしたイベントを長押しする方法を教えてください。

4

2 に答える 2

3

このコードを確認してください

//Add Long Press Gesture Reconizer
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
                                      initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 3; //seconds
longPress.delegate = self;
[yourButton addGestureRecognizer:longPress];

//Add button touch
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[yourButton addGestureRecognizer:tapGesture];
//For touch you can also set selector for button event with Controlevent touchupinside


-(void) handleLongPress : (id)sender
{
   //Long Press done by the user
}

-(void) tapDetected : (id) sender
{
   //Button Tapped by user
}
于 2012-08-30T13:17:29.427 に答える
1

NSTimer を使用して、ボタンの「タッチダウン」イベントと「タッチアップ」イベントの間の時間を測定できます。

次に、「長押し」のしきい値を定義し、継続時間のしきい値を超えた場合にタッチアップ イベントを「長押し」として処理します。

于 2012-08-30T12:53:31.667 に答える