我有2个UIScrollView
我有UITableView
显示数据
我在UICollectionView
UITableView
view
| - UITableView
| - UICollectionView
UITableView
只能垂直滚动,而UICollectionView
只能水平滚动。我只能滚动collectionview
不重叠的桌面视图(这是偏离预期的行为),但我需要这样做,以便即使我垂直滑动tableview
也可以滚动collectionview
{1}}。
我不能简单地将collectionview
添加为tableview
的子视图,因为其他原因(我知道,这会使这项工作)
还有其他可能让collectionview
passthrough与tableview
接触吗?
答案 0 :(得分:4)
您可以尝试创建UICollectionView
的子类,并将此代码添加到CustomCollectionView
的.m文件中。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self) {
return nil;
} else {
return hitView;
}
}
答案 1 :(得分:3)
据我了解,您希望UITableView以及UICollectionView拦截触摸?
我认为您可以尝试将触摸事件从UICollectionView重新发送到UITableView。 (手动调用touchesBegin,touchesMoved,touchesEnded等)
也许覆盖touchesBegan,touchesMoved,touchesEnded方法将适用于您的情况。
您可以尝试使用您的子类覆盖UICollectionView(将属性设置为您的UITableView实例)并使用以下内容实现触摸处理方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
if (CGRectContainsPoint(self.tableView.frame, [touch locationInView:self.tableView.superview]) {
[self.tableView touchesBegan:touches withEvent:event];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
[self.tableView touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self.tableView touchesEnded:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
[self.tableView touchesCancelled:touches withEvent:event];
}
希望它会有所帮助,但我不能100%肯定它。
我也发现了这篇文章,也许它会很有用
http://atastypixel.com/blog/a-trick-for-capturing-all-touch-input-for-the-duration-of-a-touch/
答案 2 :(得分:1)
您可以在collectionview上添加方向垂直的平移手势识别器。在垂直平移事件上,您可以更改表视图的内容偏移以滚动它。