سؤال

وكيف يمكننا الكشف عن الحنفية وعقد على UITableViewCell؟

هل كانت مفيدة؟

المحلول

في دائرة الرقابة الداخلية 3.2 أو في وقت لاحق يمكنك استخدام <لأ href = "http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UILongPressGestureRecognizer_Class/Reference/Reference.html" يختلط = "noreferrer" > 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