Hero: Transparent Background on Slide Animation for Navigation Controller

Created on 12 Feb 2018  路  5Comments  路  Source: HeroTransitions/Hero

Hey lkzhao, thanks for the awesome library :) . Working on a new app and really looking forward to using it.

One thing I haven't been able to figure out, and I've been digging through your Wiki and code to try to figure out:

I have a UINavigationController with a transparent background, embedded in a UIViewController with a big UIImageView background. So the NavCon is transparent and I can see a picture of, say, dolphins.

I want to use a sliding animation, so I did this:

navController.heroNavigationAnimationType = .selectBy(presenting: .slide(direction: .left), dismissing: .slide(direction: .right))

I turned on Hero Enabled on the nav controller in my storyboard, and now this works. I can see Hero taking over the animations and so on. I'm replacing the root view controller like so:

navController.setViewControllers([newViewController], animated: true)

However, the problem is that when the animation starts, the background flashes to black. I can't totally tell if it's the background of the NavCon, or perhaps the backgrounds of both the dismissed & presented view controllers, but I completely lose my background image that's shining through the NavCon's transparent background.

I feel like this might be because of Hero's behavior in terms of snapshotting views for transitions, so I tried to add the .useNoSnapshot modifier on...everything. The NavCon, both VCs, subviews, etc. but it didn't seem to help. I also unchecked isOpaque on as much stuff as I could but again, didn't seem to do anything.

Would you be able to point me in the right direction? I'd really not like to fall back to rolling all my own transitions, but I need to keep that background image shining through.

Most helpful comment

Oh wow, got it.

Hero.shared.containerColor = .clear

That solved my problem. I may or may not have needed to tweak those snapshot settings and opacity, but this was the final ingredient.

Thanks @lkzhao and I hope this issue's existence will help anyone who comes along with the same problem!

All 5 comments

Oh wow, got it.

Hero.shared.containerColor = .clear

That solved my problem. I may or may not have needed to tweak those snapshot settings and opacity, but this was the final ingredient.

Thanks @lkzhao and I hope this issue's existence will help anyone who comes along with the same problem!

Where to insert that code @tooolbox

Unfortunately that was 2 years ago and I don't recall.

Probably in some init of something; it looks like a run-once piece of code.

Why don't you try it in a few places and post back here what works best?

I tried several places and screen is still black. I am presenting VC that has half opacity @tooolbox

You need to add in didFinishLaunchingWithOptions @yarodevuci

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        Hero.shared.containerColor = .clear
        return true
    }


Was this page helpful?
0 / 5 - 0 ratings

Related issues

TofPlay picture TofPlay  路  4Comments

brendan-guegan-orange picture brendan-guegan-orange  路  4Comments

cristinaITdeveloper picture cristinaITdeveloper  路  4Comments

BalestraPatrick picture BalestraPatrick  路  3Comments

LucaGalaxy picture LucaGalaxy  路  4Comments