MSPeekCollectionViewDelegateImplementation
MSPeekCollectionViewDelegateImplementation copied to clipboard
Issue when switching orientation
Hey, there's an issue when switching orientation.
When I tried to select programmatically a cell, the selected cell is scrolled weirdly
Here is my codes:
var selectedItemIndex = 0
func selectAnItem(){
let itemContentOffset = peekImplementation.scrollView(collectionView, contentOffsetForItemAtIndex: selectedItemIndex)
collectionView.setContentOffset(CGPoint(x: itemContentOffset, y: 0), animated: false)
}
override func viewWillLayoutSubviews() {
selectAnItem()
}
func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didChangeActiveIndexTo activeIndex: Int) {
print("Changed active index to \(activeIndex)")
selectedItemIndex = activeIndex
}
func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didSelectItemAt indexPath: IndexPath) {
print("Selected item at \(indexPath)")
}
a Gif:
For users having this issue, you can do this:
override func draw(_ rect: CGRect) {
super.draw(rect)
self.collectionView.collectionViewLayout.invalidateLayout()
self.selectAnItem()
}
Thanks @HassanTaleb90 for raising this issue! Are you using the collection view inside another view or cell or its just in the view controller?
Welcome @MaherKSantina . I used it in a table view cell
Ohh okay nice! Thanks for sharing your solution with me! Do you think you can make a pull request on the documentation (Readme.md) to add this information so that others don't experience the same problem?