문제

우리는 탭을 어떻게 감지하고 UITableViewCell?

도움이 되었습니까?

해결책

iOS 3.2 이상에서 사용할 수 있습니다 UILongPressGestureRecognizer

다른 팁

내 앱에서 바로 들어 올린 코드는 다음과 같습니다. 이 메소드 (및 부울 _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];
}
//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