HeroTransitions / Hero

Elegant transition library for iOS & tvOS
https://HeroTransitions.github.io/Hero/
MIT License
22.06k stars 1.73k forks source link

Transition to a CollectionViewCell #555

Closed conanm closed 2 years ago

conanm commented 6 years ago

I want to transition from a ViewController to a ViewController with a CollectionView that pages horiziontally and presents cells as fullscreen views to paginate through 100s of model objs. It would work smoothly if I could dequeue the cellForItemAtIndexPath and then transition (using hero IDs) from the existing screen to the cell. The problem is, to dequeue the cell it needs to be visible. So again,

Anyone implement this use case? Some ways I could do it:

Thanks.

maxydey commented 5 years ago

It's pretty simple. I did it implementing Instagram Stories behaviour. All you need is force render collectionView of presented fullscreen VC

 override func viewDidLoad() {
        super.viewDidLoad()
        collectionView.layoutIfNeeded() // force load cells before scrolling to the index
        collectionView.scrollToItem(at: IndexPath(item: selectedIndex, section: 0), at: .centeredHorizontally, animated: false)
}