Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

targetContentOffset(forProposedContentOffset:) in my CustomFlowLayout not called

I am writing a custom UICollectionViewFlowLayout which overrides targetContentOffset(forProposedContentOffset:) in order to provide right contentOffset when user pinch to zoom since I get this problem (wrong 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
    }
}

But unfortunately targetContentOffset is not called, do you have an idea why?

Thanks!

Thierry

like image 673
thierryb Avatar asked Nov 26 '25 10:11

thierryb


1 Answers

try with

override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint 
like image 165
Ivailo Kanev Avatar answered Nov 28 '25 01:11

Ivailo Kanev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!