我在同一个视图控制器上使用了UITableView和UICollectionView。
我想要更改UICollectionView的滚动方式,所以我在扩展中添加了scrollViewWillBeginDragging和scrollViewWillEndDragging函数。
然而,即使不在同一扩展中,scrollViewWillBeginDragging和scrollViewWillEndDragging也会影响UITableView。
如何解决这个问题?有没有办法只选择UICollectionView?
以下是我的代码简化版:
我想要更改UICollectionView的滚动方式,所以我在扩展中添加了scrollViewWillBeginDragging和scrollViewWillEndDragging函数。
然而,即使不在同一扩展中,scrollViewWillBeginDragging和scrollViewWillEndDragging也会影响UITableView。
如何解决这个问题?有没有办法只选择UICollectionView?
以下是我的代码简化版:
extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
// This is where I put all of the UICollectionView code, including `scrollViewWillBeginDragging` and a `scrollViewWillEndDragging`
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
// Why is the code in here affecting the UITableView?
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
// Same as with `scrollViewWillBeginDragging`
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
// This is where I put all of the UITableView code, it's separate from the UICollectionView so why are `scrollViewWillBeginDragging` and `scrollViewWillEndDragging` affecting it?
}
if let view = scrollview.superView, view == collectionView {}
就像这样。 - Coder ACJHP