PagingView
PagingView copied to clipboard
Disable infinite looping issue
Hi
When I set infinite looping flag to false.
Now scroll the page to 1/2/3... from 0 manually, assume the index comes to 2.
Then use the api pagingView.scrollToPosition(.center, indexPath: IndexPath(item: 0, section: 0), animated: false)
Ok, now the index is 0, but this time infinite scrolling is turned on again. I can scroll to 4 directly, just like the infinite looping flat fails.
Here is the code
class DemoViewController: UIViewController {
@IBOutlet weak var pagingView: PagingView!
var colors: [UIColor] = ["0", "1", "2", "3", "4", "5"].map({ _ in UIColor.randomColor })
override func viewDidLoad() {
super.viewDidLoad()
pagingView.dataSource = self
pagingView.delegate = self
pagingView.pagingMargin = 0
pagingView.pagingInset = 0
pagingView.infinite = false
pagingView.showsHorizontalScrollIndicator = false
let nib = UINib(nibName: "DemoViewCell", bundle: nil)
pagingView.registerNib(nib, forCellWithReuseIdentifier: "DemoViewCell")
}
@IBAction func scrollManually(_ sender: Any) {
pagingView.scrollToPosition(.center, indexPath: IndexPath(item: 0, section: 0), animated: false)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension DemoViewController: PagingViewDataSource, PagingViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let centerCell = pagingView.visibleCenterCell() {
title = "\(centerCell.indexPath.item)"
}
}
func pagingView(_ pagingView: PagingView, numberOfItemsInSection section: Int) -> Int {
return colors.count
}
func pagingView(_ pagingView: PagingView, cellForItemAtIndexPath indexPath: IndexPath) -> PagingViewCell {
let cell = pagingView.dequeueReusableCellWithReuseIdentifier("DemoViewCell")
if let cell = cell as? DemoViewCell {
let color = colors[indexPath.item]
cell.backgroundColor = color
cell.label.text = "\(indexPath.item)"
}
return cell
}
}
Here is the demo video: https://user-images.githubusercontent.com/16531533/170958760-dee49e3e-9e80-4b70-a840-4aebf9c72849.mov
@jackdebugging Thanks for the issue. I'll try to fix it, but I'm busy recently so it can't be fixed immediately.