gpt4 book ai didi

ios - UICollectionView 的 scrollToItem 没有调用 targetContentOffset

转载 作者:行者123 更新时间:2023-11-28 08:14:59 24 4
gpt4 key购买 nike

我有一个实现分页的 Collection View ,这就是为什么我在自定义 UICollectionViewFlowLayout 中覆盖 targetContentOffset 来处理它。当通过用户交互滚动 Collection View 并且它起作用时,它会被调用。但是,在使用 scrollToItem 或滚动到可见矩形时不会调用它。通过 targetContentOffset 方法以编程方式滚动到 Collection View 的最佳方式是什么?

最佳答案

在我的例子中,我使用了以下方法以编程方式维护分页和滚动。

func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if scrollView.contentOffset.y > -topHeaderView.frame.size.height && scrollView.contentOffset.y < -20 - 50 {
let aHeaderHeight = topHeaderView.frame.size.height
if velocity.y <= 0 {
targetContentOffset.memory = CGPoint(x: 0, y: -aHeaderHeight)
} else {
targetContentOffset.memory = CGPoint(x: 0, y: 20 + 50)
}
}
}

希望对您有所帮助。

关于ios - UICollectionView 的 scrollToItem 没有调用 targetContentOffset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42826197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com