Skip to content

Instantly share code, notes, and snippets.

View dsk1306's full-sized avatar

Dmitrii Kuznetsov dsk1306

View GitHub Profile
@dsk1306
dsk1306 / CollectionViewPaging.swift
Created September 6, 2018 08:05
Custom UIScrollView paging
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let pageWidth = <#page width#>
let collectionViewContentWidth = collectionView.contentSize.width
if velocity.x == 0 {
page = Int(floor((targetContentOffset.pointee.x - pageWidth / 2) / pageWidth) + 1.0)
} else {
page = velocity.x > 0 ? page + 1 : page - 1
if page < 0 {
page = 0