gpt4 book ai didi

swift - targetContentOffset(forProposedContentOffset :) in my CustomFlowLayout not called

转载 作者:行者123 更新时间:2023-12-05 01:19:21 24 4
gpt4 key购买 nike

我正在编写一个自定义的 UICollectionViewFlowLayout,它覆盖了 targetContentOffset(forProposedContentOffset:),以便在用户缩放时提供正确的 contentOffset,因为我遇到了这个问题(错误的 contentOffset)

Dynamically setting layout on UICollectionView causes inexplicable contentOffset change

class TimelineCollectionViewFlowLayout: UICollectionViewFlowLayout {

// MARK: - Init

override init() {
super.init()
self.minimumLineSpacing = 0
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func prepare() {
if let collectionView = self.collectionView {
collectionView.isPagingEnabled = false
self.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
self.scrollDirection = .horizontal
}
}

override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
print("hello")
return proposedContentOffset
}
}

但不幸的是 targetContentOffset 没有被调用,你知道为什么吗?

谢谢!

蒂埃里

最佳答案

试试

override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint 

关于swift - targetContentOffset(forProposedContentOffset :) in my CustomFlowLayout not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40490567/

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