UIScrollView 中 UITableView 上的冲突滚动 [英] Conflictive scroll on UITableView within UIScrollView

查看:37
本文介绍了UIScrollView 中 UITableView 上的冲突滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 UIScrollView(pagingEnable = YES) 中包含了三个 UITableView

I had three UITableViews contained in one UIScrollView(pagingEnable = YES),

层次结构如下:

                                 +--visible area--+  ---+
+---------`UIScrollView`---------+---------------+|  --+|
| +-------------+ +-------------+|+-------------+||  -+||
| |      0      | |      1      |||      2      |||   |||
| |`UITableView`| |`UITableView`|||`UITableView`|||  equal height
| |             | |             |||             |||   |||
| +-------------+ +-------------+|+-------------+||  -+||
+--------------------------------+---------------+|  --+| 
                                 +----------------+  ---+

UIScrollView(作为容器视图)的contentSize.height 设置为适合屏幕高度,因此它只能滚动在水平 方向.并且每个 UITableView 都可以垂直滚动.

The UIScrollView (as container view) had it'scontentSize.height set to fit the screen height, thus it's only scrollable in horizontal direction. And each UITableView is vertically scrollable as is.

问题是我不知道哪个视图(ScrollViewTableView)处理屏幕上的当前手指触摸.

The problem is I have no idea which view (ScrollView or TableView) handle a current finger touch on the screen.

当我在屏幕上滚动完美的垂直/水平路径以移动 ScrollViewTableView 时,它工作正常.

It works fine when I scroll a perfect vertical / horizontal path through the screen to move the ScrollView or TableView.

虽然如果我从右下角滚动到左上角(如反斜杠\"),它有时会水平移动 ScrollView,有时会垂直移动 TableView ......code>TableView 可笑.我就是无法移动我所期望的.

While if I scroll from the bottom right to the top left (like a backslash "\") it sometimes move the ScrollView horizontally, sometimes move the TableView vertically...even worse it move none of both but just shake the TableView ridiculously. I just can't move what I expected.

我认为是因为UIScrollViewUITableView 的ScrollView 有检测冲突.

I assume it's because UIScrollView and UITableView's ScrollView have detection conflict .

这里我在 UIScrollViewDelegate 方法中添加了日志:

Here I added log to the UIScrollViewDelegate method:

//in each ViewController handle a UITableView

    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
            NSLog(@"TableView touched")
        }
    }

//in the ViewController handle the UIScrollView

    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
            NSLog(@"ScrollView touched")
        }
    }

//as a side note...I set three ViewControllers(each holds one TableView) into a ContainerViewController(holds ScrollView)

他们一个接一个地随机退出……但几乎在同一时间.

They logged out one after another randomly...but almost the same time.

任何想法将不胜感激!

推荐答案

为整个视图添加一个 UIPanGestureRecognizer.存储初始位置,并从当前位置计算是水平移动还是垂直移动.(如果 x 坐标的变化大于水平,如果 y,则为垂直.)

Add a UIPanGestureRecognizer for the entire view. Store the initial location, and from the current location, calculate if it is a horizontal or vertical movement. (If the x coordinate is changing more, than it is horizontal, if y, vertical.)

一旦方向明确,向前移动到表格视图或滚动视图.

Once the direction is clear, forward the movement to the table view or the scroll view.

或者更好的解决方案:使用表格视图控制器并添加边缘滑动手势来切换,就像它们在选项卡控制器中一样.

Or a better solution: use a table view controller and add edge swipe gestures to switch like if they were in a tab controller.

这篇关于UIScrollView 中 UITableView 上的冲突滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆