HeroTransitions / Hero

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

UIVisualEffectView transition #26

Closed felix-dumit closed 6 years ago

felix-dumit commented 7 years ago

I added a UIVisualEffectView to the MusicPlayer example to simulate this issue. It breaks during the transition and also after the transition is complete it's still not the way it should be.

Hero off

Hero off

Hero on

Hero on

Console outputs this warning:

[Warning] <UIVisualEffectView 0x7fa50e80b830> is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.

Code used is available here: https://github.com/felix-dumit/Hero/tree/visual-effect-snapshot

Any ideas? Maybe take a snapshot of the window at the effectView (final) bounds?

I played around with this idea here: 7d9f0f11a4c7e94d26fb48f4b0ad25dcd51e10ea

Still needs some work but here is an initial result: Temp anim It still breaks once the animation is complete, though.

This is probably an unrelated question, but in the above scenario, how could I make it so the effectView frame doesn't animate (i.e it already starts with the the final frame)?

fruitcoder commented 7 years ago

I haven't looked at the exact code that peforms the animations, but is it possible to check for the views that are animated (traversing the view hierarchy)? Then every VisualEffectView's effect would be set to nil and reset in an animation block. That way it could be animated

lkzhao commented 7 years ago

With the new .overFullScreen support. This should be possible. We just have to figure out how to animation UIVisualEffectView, since it doesn't support opacity animation.

fruitcoder commented 7 years ago

As I said UIVisualEffectView can animate its blur by setting the effect from nil to a blur effect in an animation block so you might have to make a special case if a view is a UIVisualEffectView and the opacity is to be animated

lkzhao commented 7 years ago

Yes, but that doesn't allow interactive scrubbing or reversing the animation.

fruitcoder commented 7 years ago

For that you have to set the blur with a UIViewPropertyAnimator and then scrub by setting it's progress

fruitcoder commented 7 years ago

But that's iOS 10+

lkzhao commented 7 years ago

I tried implementing the UIViewPropertyAnimator. I modify to menu example to have a blur background.

http://lkzhao.com/video/?path=%5Cpublic%5Cposts%5Chero%5Cmenu.mov

It doesn't works when it is interactive though. Whenever, I set the .fractionComplete, the blur effect immediately jumps to the end.

felix-dumit commented 7 years ago

Maybe if it's interactive you have to take a snapshot of the view and animate its alpha similar to the way I tried to do it?

felix-dumit commented 7 years ago

@lkzhao Actually the way you tried should work, check out this example project: https://github.com/fichek/AnimateBlurRadius/

felix-dumit commented 7 years ago

I think the problem is here: https://github.com/lkzhao/Hero/blob/master/Sources/HeroViewPropertyViewContext.swift#L59 Since it already starts the animation immediately, if it is interactive it shouldn't do that and only rely on the fractionComplete.

jegnux commented 7 years ago

If you set the UIVisualEffectView as your's UIViewController.view in loadView(), then the transition is automatically handled by UIKit. Maybe it'll solve your issue.