質問

タップとアンプを検出する方法 UITableViewCell を保持しますか?

役に立ちましたか?

解決

iOS 3.2以降では、 UILongPressGestureRecognizer

他のヒント

これは、アプリから直接持ち上げたコードです。 UITableViewCellから派生したクラスにこれらのメソッド(およびブール値の_cancelTouchesメンバー)を追加する必要があります。

-(void) tapNHoldFired {
    self->_cancelTouches = YES;
   // DO WHATEVER YOU LIKE HERE!!!
}
-(void) cancelTapNHold {
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(tapNHoldFired) object:nil];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self->_cancelTouches = NO;
    [super touchesBegan:touches withEvent:event];
    [self performSelector:@selector(tapNHoldFired) withObject:nil afterDelay:.7];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self cancelTapNHold];
    if (self->_cancelTouches)
        return;
    [super touchesEnded:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    [self cancelTapNHold];
    [super touchesMoved:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [self cancelTapNHold];
    [super touchesCancelled:touches withEvent:event];
}
//Add  gesture to a method where the view is being created. In this example long tap is added to tile (a subclass of UIView):

    // Add long tap for the main tiles
    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
    [tile addGestureRecognizer:longPressGesture];
    [longPressGesture release];

-(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer{
    NSLog(@"gestureRecognizer= %@",gestureRecognizer);
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        NSLog(@"longTap began");

    }

}

おそらく UIControlTouchDown イベントを処理し、「ホールド」の意味に応じて、タッチを開始してから間隔をカウントするNSTimerを起動し、タッチを起動または解放すると無効になります( UIControlTouchUpInside および UIControlTouchUpOutside イベント)。タイマーが作動すると、"タップ&ホールド"検出されました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top