UIPanGestureRecognizer on UITableViewCell overrides UITableView's scroll view gesture recognizer

后端 未结 4 1554
终归单人心
终归单人心 2020-12-31 02:26

I\'ve subclassed UITableViewCell and in that class I apply a Pan gesture recogniser:

UIPanGestureRecognizer *panning = [[UIPanGestureRecognizer          


        
相关标签:
4条回答
  • 2020-12-31 02:52

    Add the gesture recogniser On tableview. From that, you can get the cell object. From there you can handle the cell Functionality. For each gesture, there will be a begin, changed, end state. So, store the begin position.

        CGPoint beginLocation = [gesture locationInView:tblView]; // touch begin state.
    
        CGPoint endLocation = [gesture locationInView:tblView]; // touch end state.
    

    Using this point, you can get the IndexPath

        NSIndexPath *indexPath = [tblView indexPathForRowAtPoint:beginPoint];
    

    From this indexpath, you can access the cell.

                UITableViewCell *cell = [tableview cellForRowAtIndexPath : indexPath];
    

    Using this Cell object, you can handle it.

    0 讨论(0)
  • 2020-12-31 02:55

    Subclass the panning gesture recognizer and make it recognize only horizontal panning. There is a great WWDC 2010 video on the issue of custom gesture recognizers available. Actually there are two on that subject, check them out at https://developer.apple.com/videos/archive/:

    • Simplifying Touch Event Handling with Gesture Recognizers
    • Advanced Gesture Recognition
    0 讨论(0)
  • 2020-12-31 02:57

    Have you tried setting pannings delegate property?

    panning.delegate = /* class name with the delegate method in it */;
    

    You'll also need to conform that class to UIGestureRecognizerDelegate.

    0 讨论(0)
  • 2020-12-31 03:17

    Have you tried setting the bounces property to NO?

    0 讨论(0)
提交回复
热议问题