Skip to content

Instantly share code, notes, and snippets.

@hsleedevelop
Last active December 6, 2018 05:01
Show Gist options
  • Select an option

  • Save hsleedevelop/e6c3f180448f34fcb4d76575b7443f53 to your computer and use it in GitHub Desktop.

Select an option

Save hsleedevelop/e6c3f180448f34fcb4d76575b7443f53 to your computer and use it in GitHub Desktop.
Draggin Inifite scroll of Collectionview
func scrollFromDragging() {//need pageEnabled.
guard let scrollView = self.collectionView else { return }
var index = Int((scrollView.contentOffset.x) / (scrollView.frame.width))
guard currentIndex != index, let banners = banners, rolling == false, isDragging == true else {
return
}
var condition = currentIndex < 0 ? 0 : 3
condition = index == 0 && currentIndex >= 0 ? 1 : condition
condition = index >= banners.count + 1 ? 2 : condition
currentIndex = index
var offset = CGFloat.leastNormalMagnitude
switch condition {
case 0://최초 드래깅
index = (fakeRowCount / 2)
offset = index * scrollView.frame.width - 1
//rollingIndex = 0
Log.d("case == 0")
case 1://0번 인덱스 이전으로 드래깅시
index = (fakeRowCount / 2)
offset = (index + 1) * scrollView.frame.width - 1
Log.d("case == 1")
case 2://마지막 드래깅시
index = 0
offset = scrollView.frame.width
Log.d("case == 2")
default:
index -= 1
}
if offset > CGFloat.leastNormalMagnitude {
scrollView.setContentOffset(CGPoint(x: offset, y: 0), animated: false)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment