FSPagerView icon indicating copy to clipboard operation
FSPagerView copied to clipboard

Invalid currentIndex before scroll

Open HosseinArabbeigi opened this issue 3 years ago • 0 comments

Hi Thanks for the best pagerview in iOS.

I'm using this lib as a language picker in my project, when screen opens i will scroll to selected language, for example 2:

pagerView.scrollToItem(at: 2, animated: false)

and appearance is fine and correct language image is showing at center, but when I'm using currentIndex value is 0 before scrolling view pager (I did scroll to 2!) and then I will scroll it and checking for currentIndex, now it has right index according to selected item. briefly pager gets 0 index before user scroll. and after scroll currentIndex is right.

My pager view setting:

pagerView.isInfinite = false

let itemSize = pagerView.frame.size.height * 3/4
pagerView.itemSize = CGSize(width: itemSize height: itemSize)

pagerView.transformer = FSPagerViewTransformer(type: .linear)

Update:

Im was calling scrollToItem in viewDidLoad، then I did change that to:

DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
           self?.pagerView.scrollToItem(at: 2, animated: false)
}

And every thing works fine.

HosseinArabbeigi avatar Dec 22 '20 16:12 HosseinArabbeigi