【发布时间】:2021-05-17 09:36:14
【问题描述】:
当用户滑动时,我在scrollViewWillEndDragging 中运行一些代码,我需要targetContentOffset.pointee.y 来执行此操作:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let yAxis = targetContentOffset.pointee.y
let visibleItem = Int(yAxis / collectionView.frame.height)
// do something with visibleItem based on cell's current vertical scroll position...
}
问题是我也做了一些自动滚动,用户不必刷卡并且 cv 自动滚动。我仍然需要访问targetContentOffset.pointee.y,所以我可以对 visibleItem 做一些事情,但它所在的方法不会在自动滚动时触发。
如何以编程方式访问 targetContentOffset.pointee.y?
【问题讨论】:
-
你如何自动滚动?
-
竖屏,全屏,我用这个:
collectionView.scrollToItem(at:IndexPath(item: xyz, section: 0), at: .centeredVertically, animated: true)
标签: ios swift uicollectionview uiscrollview