applidium / OverlayContainer

Non-intrusive iOS UI library to implement overlay based interfaces
https://gaetanzanella.github.io/2018-12-17/replicating-apple-maps-overlay
Other
1.15k stars 94 forks source link

Duration of animation for moveOverlay #41

Closed sfla closed 4 years ago

sfla commented 4 years ago

This is more of a request for help than an issue, I guess, but I can't figure out how to set the duration of the animation when calling moveOverlay(toNotchAt:,animated:). I even considered importing the entire OverlayContainer as classes instead of a pod so I could manipulate it if it was private, but I can't find a duration anywhere, just velocity and advanced animation protocols. It would be nice to make it animate alongside another animation too, but I just don't understand how. The ShowOverlayExample just uses the basic "moveOverlay" with the default duration, so it couldn't help me..

gaetanzanella commented 4 years ago

Hi @sfla, the overlay container CV will use the OverlayAnimatedTransitioning provided by its delegate to animate a translation (ref). You can provide your own object to modify the animation. Implement:

    func overlayContainerViewController(_ containerViewController: OverlayContainerViewController,
                                        transitioningDelegateForOverlay overlayViewController: UIViewController) -> OverlayTransitioningDelegate?

Note that by default the container uses the SpringOverlayTranslationAnimationController which uses this UISpringTimingParameters init under the hood. So, the animation is entirely based on physics, the duration parameter is actually 0.

See this to animate things alongside the overlay translation.

sfla commented 4 years ago

Great! Thanks. I haven't used (animateAlongside:) with transitionCoordinator and context etc. that much in the past, so I'll look into it. The challenge is that I want it the other way around; to make the overlay animate alongside another animation.

gaetanzanella commented 4 years ago

You can try to move the overlay without animation and call layoutIfNeeded on any view that contains it (or on its view if it's already the root view) . Something like:

UIView.animate(withDuration: 1) {
     self.overlayContainer.moveOverlay(toNotchAt: 0, animated: false)
     self.view.layoutIfNeeded()
}

It should override all the internal animation behavior.

sfla commented 4 years ago

Oh man. I tried that yesterday, but didn't include the layoutIfNeeded(), Thanks!

pabsanmez commented 4 years ago

Thank you! :) This has saved my day :)! BTW @gaetanzanella this library is really really awesome! Thank you for putting so much effort on it and let the others use it :)