タップアンドホールドを検出するにはどうすればよいUITableViewCell
ですか?
7794 次
4 に答える
9
iOS 3.2以降で使用できますUILongPressGestureRecognizer
于 2010-12-21T13:28:06.377 に答える
6
これが私のアプリから直接持ち上げられたコードです。これらのメソッド (およびブール値の _cancelTouches メンバー) を、UITableViewCell から派生したクラスに追加する必要があります。
-(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];
}
于 2010-01-28T17:26:29.067 に答える
6
//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");
}
}
于 2011-06-04T04:28:18.203 に答える
0
おそらくUIControlTouchDownイベントを処理し、「ホールド」の意味に応じて、タッチを開始してから間隔をカウントし、タッチの発火または解放時に無効にするNSTimerを起動する必要があります(UIControlTouchUpInsideおよびUIControlTouchUpOutsideイベント)。タイマーが作動すると、「タップ&ホールド」が検出されます。
于 2009-10-27T21:59:47.277 に答える