我目前有一个 panGesture 识别器附加到也启用了分页的 collectionView。
问题是 panGesture 覆盖了分页。如果可能的话,我希望在 panGesture 之前执行分页操作。
我使用 panGesture 垂直移动 collectionView,并使用分页水平滑动单元格。
最佳答案
我们可以通过检测 collectionview 的滚动来实现相同的功能,无需 PanGesture 。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let visibleRect = CGRect(origin: collectionViewCreateNewGame.contentOffset, size: collectionViewCreateNewGame.bounds.size)
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
let indexPath = collectionViewCreateNewGame.indexPathForItem(at: visiblePoint)
pageControl.currentPage = (indexPath?.row)!
}
关于ios - 如何通过 panGestureRecognizer 启用 collectionView 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48862108/