Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

ios - Custom ViewController transition – Should I animate snapshots or actual views?

I'm curious what is the proper way of doing custom view controllers transitions nowadays.

I know there can be many approaches depending on a difficulty of a desired transition. From simple self-contained view controllers where I handle everything (e.g. custom Alert), to interactive transitions, where I use helper classes and so animation is not happening in the concrete view controller.

Example transition:

Let's take a look at the example I want to do:

There is MainViewController and DetailViewController which should slide out from the top. It should look like it uses the same view (see the paper for the desired flow, screenshots for current "wrong" implementation) = buttons should fade out and the view should start expanding while fade in of the textfields and also black overlay. It should behave quite similar on dismissal (which should be interactive).

desired flow

screenshots

Now the question:

How to properly handle the animation in case I use some helper class as an Animator? (e.g. class ContentAnimator: NSObject, UIViewControllerAnimatedTransitioning { ... } )

  • Should I pass snapshots of all views and animate snapshots in func animateTransition(using transitionContext: UIViewControllerContextTransitioning) ?
  • Or should I pass views and animate them directly?
  • Or should I downcast viewControllers in that function and access those views there?
        let fromViewController = transitionContext.viewController(forKey: .from) as? MainViewController
        let toViewController = transitionContext.viewController(forKey: .to) as? DetailViewController
        
        ...
        
    animator.addAnimation {
        fromViewController?.buttons.alpha = 0
        toViewController?.view.frame =  XY
        toViewController?.blackoverlay.alpha = 1
    }

Is there any danger when I animate the views directly? I will be happy if you can point me in the right direction.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...