将垂直滚动手势传递到下面的UITableView

can*_*boy 12 iphone objective-c uitableview uigesturerecognizer ios

(为清晰起见编辑)

我有一个UITableView.最重要的是附有Pan手势的UIView.此Pan向左和向右滑动以更改基础表.我使用平移手势的动作方法来移动表格.工作正常.

但是,UIView及其Pan手势会干扰向上/向下滚动UITableView.如何将向上/向下滚动发送到表格并保持左右视图的区域?

 ---------------------------------------
 |                                     |
 |             ----------------------  |
 |             |                    |  |
 |             |                    |  |
 |             |                    |  |
 | UITableView |                    |  |
 |             |        UIView      |  |
 |             |          +         |  |
 |             |       PanGesture   |  |
 |             |                    |  |
 |             |                    |  |
 |             |                    |  |
 |             |                    |  |
 |             ----------------------  |
 |                                     |
 |                                     |
 ---------------------------------------
Run Code Online (Sandbox Code Playgroud)

Pan手势触发的方法是这样的

 -(void)move:(UIPanGestureRecognizer*)sender
 {
     CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
     float xTest = fabsf(translatedPoint.x);
     float yTest = fabsf(translatedPoint.y);
     if ( xTest>yTest)
     {
         // Move table view left-right.. this works
     } else
     {
         // Send up-down scrolling gesture to table view????? How to?
     }
 }
Run Code Online (Sandbox Code Playgroud)

小智 12

我刚刚解决了类似的问题,除了它是垂直平底锅而不是水平平底锅.我对你的用例并不是100%肯定,所以这可能不是你想要的,但它可能会引导你朝着正确的方向前进.

我对UIPanGestureRecognizer进行了细分,并实现了touchesMoved方法,并检查手势是否有更大的水平或垂直变化.下面是一个片段.该信用属于不同的stackoverflow帖子,但我目前无法找到该链接.(提前抱歉格式不佳,第一次发帖)

-(void)touchesMoved:(NSSet*) touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
if(self.state == UIGestureRecognizerStateFailed) return;
CGPoint currentPoint = [[touches anyObject] locationInView:self.view];
CGPoint prevPoint = [[touches anyObject] previousLocationInView:self.view];
moveX += prevPoint.x - currentPoint.x;
moveY += prevPoint.y - currentPoint.y;
if(!drag) {
    if(abs(moveY) > abs(moveX))
        drag = YES;
    else
        self.state = UIGestureRecognizerStateFailed;
}
}

-(void)reset
{
[super reset];
drag = NO;
moveX = 0;
moveY = 0;
}
Run Code Online (Sandbox Code Playgroud)

在我的父视图控制器中,我相信在这种情况下是UITableView,我也实现了以下内容.我认为在你的情况下,如果它是一个水平平移,你会想要返回no.

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if([gestureRecognizer isKindOfClass:[VerticalPanGestureRecognizer class]])
{
    return YES;
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)

如果有任何不清楚的地方,请告诉我.

祝好运!