将垂直滚动手势传递到下面的UITableView [英] Passing vertical scrolling gesture to UITableView below
问题描述
(为清晰起见编辑)
我有一个UITableView。最重要的是附有Pan手势的UIView。此Pan向左和向右滑动以更改基础表。我使用平移手势的动作方法来移动表格。工作正常。
I have a UITableView. On top of that is a UIView with a Pan gesture attached. This Pan swipes left and right to change the underlying table. I use the pan gesture's action method to move the table. That working fine.
然而,UIView&它的Pan手势会干扰向上/向下滚动UITableView。如何将向上/向下滚动发送到桌面并在视图区域保持左右?
However, the UIView & its Pan gesture interferes with up/down scrolling the UITableView. How can I send the up/down scrolling to the table and keep the left-right on the view's area?
---------------------------------------
| |
| ---------------------- |
| | | |
| | | |
| | | |
| UITableView | | |
| | UIView | |
| | + | |
| | PanGesture | |
| | | |
| | | |
| | | |
| | | |
| ---------------------- |
| |
| |
---------------------------------------
Pan手势触发的方法就像这样
The method triggered by the Pan gesture is like this
-(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?
}
}
推荐答案
我刚刚解决了类似的问题,除了它是垂直平底锅而不是水平平底锅。我对你的用例并不是100%肯定,所以这可能不是你想要的,但它可能会引导你朝着正确的方向发展。
I just solved a similar problem, except it was for vertical pans instead of horizontal ones. I'm not 100% sure about your use case, so this may not be what your looking for, but it may lead you in the right direction.
我分归类为UIPanGestureRecognizer,并实现了touchesMoved方法,并检查手势是否有更大的水平或垂直变化。以下是一个片段。该信用属于不同的stackoverflow帖子,但我目前找不到该链接。 (抱歉格式不佳,第一次发帖)
I sub-classed UIPanGestureRecognizer, and implemented the touchesMoved method, and checked to see whether the gesture had a larger horizontal or vertical change. Below is a snippet. The credit belongs to a different stackoverflow post, but I cannot find the link at the moment. (Sorry in advance for the poor formatting, first time posting)
-(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;
}
在我的父视图控制器中,我相信在这种情况下是UITableView ,我也实现了以下内容。我认为在你的情况下,你想要返回no,如果它是一个水平平底锅。
In my parent view controller, which I believe would be the UITableView in this case, I also implemented the following. I think in your case, you'd want to return no if it's a horizontal pan.
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if([gestureRecognizer isKindOfClass:[VerticalPanGestureRecognizer class]])
{
return YES;
}
return NO;
}
如果有任何不清楚的地方,请告诉我。
Let me know if any of this is unclear.
祝你好运!
这篇关于将垂直滚动手势传递到下面的UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!