MSPeekCollectionViewDelegateImplementation icon indicating copy to clipboard operation
MSPeekCollectionViewDelegateImplementation copied to clipboard

Issue when switching orientation

Open HassanTaleb90 opened this issue 5 years ago • 3 comments

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()
    }

HassanTaleb90 avatar Apr 19 '19 10:04 HassanTaleb90

Thanks @HassanTaleb90 for raising this issue! Are you using the collection view inside another view or cell or its just in the view controller?

MaherKSantina avatar Apr 19 '19 10:04 MaherKSantina

Welcome @MaherKSantina . I used it in a table view cell

HassanTaleb90 avatar Apr 19 '19 10:04 HassanTaleb90

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?

MaherKSantina avatar Apr 19 '19 10:04 MaherKSantina