我在CollectionView
中有TabelViewCell
,并且我正在尝试对CollectionView
的单元进行分页和居中。但是当我使用方法
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>){}
它适用于TabelView和CollectionView。我知道这些类型是从UIScrollView继承的,所以才出现这种情况。要将该方法仅应用于一种类型,需要做些什么?
答案 0 :(得分:0)
您可以通过检查scrollView的类型来做到这一点:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if scrollView is UITableView {
// Do your thing for the tableView.
} else if scrollView is UICollectionView {
// Do your thing for the collectionView.
}
}