HeroTransitions / Hero

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

Hero doesn't work without storyboard #315

Closed pbeneteau closed 7 years ago

pbeneteau commented 7 years ago

Hi,

I have a CollectionView where I subclass the cells and I add an image in all the cells. I set the image hero id to "OGImage". I have a DetailViewController where I have a background image with hero id "OGImage". I also set isHeroEnable to true.

Then, in the didSelectItemAt CollectionView protocol, I have: show(DetailController(), sender: Any.self) When I click on the cell, there is no Hero animations but the default show animation.

Hope I'm clear, thanks in advance for your help.

ajaybeniwal commented 7 years ago

Did u try setting hero id on collection view cell instead of imageview ??

pbeneteau commented 7 years ago

Hi, yes I did, doesn't work. I noticed recently: there is a strange animation. in fact, there is an animation but it is ugly. As if the cell image get bigger (screen size) instantly and slide to the left. But this is not the growing/match animation of the demo.

lkzhao commented 7 years ago

You have to set isHeroEnabled to the navigation controller if you are using one.

EgorkZe commented 7 years ago

The same problem , can not find solution(

hiroshihorie commented 7 years ago

Same problem here, too many unreliable swift libraries wasting my time....

EgorkZe commented 7 years ago

I found the solution, each cell in collection view should have own heroid; for example

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell",
                                                      for: indexPath)
        cell.heroID = "cardNum" + String(indexPath.section) + String(indexPath.row)
        return cell
    }
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller: DayDetailViewController = storyboard.instantiateViewController(withIdentifier: "DayDetailViewControllerID") as! DayDetailViewController
        controller.heroIdent = "cardNum" + String(indexPath.section) + String(indexPath.row)
            self.present(controller, animated: true, completion: nil)
    }
lkzhao commented 7 years ago

If every cell inside your collection view have the same heroId then it will not work. You have to set a unique heroId for each cell which match the heroId of the view that is presenting. For example: cell 1 might have "item-1" as heroId, and cell 2 might have "item-2". and depend on which cell you tapped on, you have to set the corresponding heroId to the view that you are presenting.

hiroshihorie commented 7 years ago

Got it working, in my case i needed to set isHeroEnabled on the UINavigationController. The first example code sets it on the UIViewController which is misleading.

It works almost as expected except there is a slight flash/fade of white when transitioning to the second controller. First controller is a grid of images and the second is larger image of the selected image so the resulting behavior should be a smooth zoom of the image.

Anyway thanks for the great library