-
-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
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)")
}
For users having this issue, you can do this:
override func draw(_ rect: CGRect) {
super.draw(rect)
self.collectionView.collectionViewLayout.invalidateLayout()
self.selectAnItem()
}
Metadata
Metadata
Assignees
Labels
No labels
