Skip to content

Issue when switching orientation #42

@HassanTaleb90

Description

@HassanTaleb90

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:
ezgif-5-098a5e011014

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions