And*_*obs 9 objective-c uitableview touches ios uicollectionview
我有2个后代 UIScrollView
我有一个UITableView显示数据,我在UICollectionView上面添加了UITableView
view
| - UITableView
| - UICollectionView
Run Code Online (Sandbox Code Playgroud)
在UITableView只能垂直滚动和UICollectionView只能水平滚动.我只能滚动我的桌面视图collectionview不重叠(这是偏离预期的行为),但我需要这样做,以便我可以滚动我tableview甚至如果我垂直刷我的collectionview.
我不能简单地将其collectionview作为子视图添加tableview因为其他原因(我知道,这将使这项工作)
有没有其他可能让de touches从collectionviewpassthrough到tableview?
据我了解,您希望 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];
}
Run Code Online (Sandbox Code Playgroud)
希望它会有所帮助,但我不是 100% 确定。
我也发现了这篇文章,也许会有用
http://atastypixel.com/blog/a-trick-for-capturing-all-touch-input-for-the-duration-of-a-touch/
| 归档时间: |
|
| 查看次数: |
921 次 |
| 最近记录: |