Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect horizontal panning in UITableView
    primarykey
    data
    text
    <p>I'm using a UIPanGestureRecognizer to recognize horizontal sliding in a UITableView (on a cell to be precise, though it is added to the table itself). However, this gesture recognizer obviously steals the touches from the table. I already got the pangesturerecognizer to recognize horizontal sliding and then snap to that; but if the user starts by sliding vertical, it should pass all events from that touch to the tableview.</p> <p>One thing i have tried was disabling the recognizer, but then it wouldn't scroll untill the next touch event. So i'd need it to pass the event right away then.</p> <p>Another thing i tried was making it scroll myself, but then you will miss the persistent speed after stopping the touch.</p> <p>Heres some code:</p> <pre><code>//In the viewdidload method UIPanGestureRecognizer *slideRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(sliding:)]; [myTable addGestureRecognizer:slideRecognizer]; -(void)sliding:(UIPanGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateBegan) { CGPoint translation = [recognizer translationInView:favoritesTable]; if (sqrt(translation.x*translation.x)/sqrt(translation.y*translation.y)&gt;1) { horizontalScrolling = YES; //BOOL declared in the header file NSLog(@"horizontal"); //And some code to determine what cell is being scrolled: CGPoint slideLocation = [recognizer locationInView:myTable]; slidingCell = [myTable indexPathForRowAtPoint:slideLocation]; if (slidingCell.row == 0) { slidingCell = nil; } } else { NSLog(@"cancel"); } if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) { horizontalScrolling = NO; } if (horizontalScrolling) { //Perform some code } else { //Maybe pass the touch from here; It's panning vertically } } </code></pre> <p>So, any advice on how to pass the touches?</p> <p>Addition: I also thought to maybe subclass the tableview's gesture recognizer method, to first check if it's horizontal; However, then i would need the original code, i suppose... No idea if Apple will have problems with it. Also: I didn't subclass the UITableView(controller), just the cells. This code is in the viewcontroller which holds the table ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload