UIScrollView 中 UITableView 上的冲突滚动
Conflictive scroll on UITableView within UIScrollView
我在一个 UIScrollView
(pagingEnable = YES
),
中包含三个 UITableView
层次结构如下:
+--visible area--+ ---+
+---------`UIScrollView`---------+---------------+| --+|
| +-------------+ +-------------+|+-------------+|| -+||
| | 0 | | 1 ||| 2 ||| |||
| |`UITableView`| |`UITableView`|||`UITableView`||| equal height
| | | | ||| ||| |||
| +-------------+ +-------------+|+-------------+|| -+||
+--------------------------------+---------------+| --+|
+----------------+ ---+
UIScrollView
(作为容器视图)contentSize.height
设置为适合屏幕高度,因此它只能 滚动水平方向。
每个 UITableView
都可以垂直滚动。
问题是我不知道哪个视图(ScrollView
或 TableView
)处理屏幕上的当前手指触摸。
当我在屏幕上滚动完美的垂直/水平路径以移动 ScrollView
或 TableView
时,它工作正常。
虽然如果我从右下角滚动到左上角(如反斜杠“\”),它有时会水平移动 ScrollView,有时会垂直移动 TableView...更糟糕的是它会移动 none两者都只是可笑地摇晃 TableView
。 我只是无法移动我所期望的。
我猜是因为UIScrollView
和UITableView
的ScrollView有检测冲突。
这里我在UIScrollViewDelegate方法中添加了日志:
//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)
他们一个接一个地随机登出……但几乎同时登出。
如有任何想法,我们将不胜感激!
为整个视图添加一个 UIPanGestureRecognizer
。存储初始位置,并从当前位置开始,计算它是水平移动还是垂直移动。 (如果 x 坐标的变化大于水平坐标,如果 y 坐标变化则为垂直坐标。)
方向明确后,将移动转发到table视图或滚动视图。
或者更好的解决方案:使用 table 视图控制器并添加边缘滑动手势来切换,就像它们在选项卡控制器中一样。
我在一个 UIScrollView
(pagingEnable = YES
),
UITableView
层次结构如下:
+--visible area--+ ---+
+---------`UIScrollView`---------+---------------+| --+|
| +-------------+ +-------------+|+-------------+|| -+||
| | 0 | | 1 ||| 2 ||| |||
| |`UITableView`| |`UITableView`|||`UITableView`||| equal height
| | | | ||| ||| |||
| +-------------+ +-------------+|+-------------+|| -+||
+--------------------------------+---------------+| --+|
+----------------+ ---+
UIScrollView
(作为容器视图)contentSize.height
设置为适合屏幕高度,因此它只能 滚动水平方向。
每个 UITableView
都可以垂直滚动。
问题是我不知道哪个视图(ScrollView
或 TableView
)处理屏幕上的当前手指触摸。
当我在屏幕上滚动完美的垂直/水平路径以移动 ScrollView
或 TableView
时,它工作正常。
虽然如果我从右下角滚动到左上角(如反斜杠“\”),它有时会水平移动 ScrollView,有时会垂直移动 TableView...更糟糕的是它会移动 none两者都只是可笑地摇晃 TableView
。 我只是无法移动我所期望的。
我猜是因为UIScrollView
和UITableView
的ScrollView有检测冲突。
这里我在UIScrollViewDelegate方法中添加了日志:
//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)
他们一个接一个地随机登出……但几乎同时登出。
如有任何想法,我们将不胜感激!
为整个视图添加一个 UIPanGestureRecognizer
。存储初始位置,并从当前位置开始,计算它是水平移动还是垂直移动。 (如果 x 坐标的变化大于水平坐标,如果 y 坐标变化则为垂直坐标。)
方向明确后,将移动转发到table视图或滚动视图。
或者更好的解决方案:使用 table 视图控制器并添加边缘滑动手势来切换,就像它们在选项卡控制器中一样。