Netzer
Netzer

Reputation: 237

Difference between UIViewControllerTransitioningDelegate and UIViewControllerContextTransitioning

I'd like to implement a custom ViewController transition. There are lot of solutions out there. Most of them are based on either UIViewControllerContextTransitioning or UIViewControllerTransitioningDelegate.

As they do mainly the same, what are differences between these methodes? (And why does Apple gives us two APIs for the same purpose?)

Thank you!

Upvotes: 0

Views: 937

Answers (2)

Vinzzz
Vinzzz

Reputation: 11724

How can you say that they do the same, have you really read the doc ? Obviously, they don't... They are both somehow related to transitions, ok for this point, but you need both for different reasons!

Basically, UIViewControllerTransitioningDelegate enables you to specify which objects are responsible for which transitions - for example, you might use the transitionDelegate of a UIViewController, to say "if there is a push transition, then MyPushTransitioner (or any other object, it could be your ViewController) is responsible for the transition"

When this is done, UIViewControllerContextTransitioning - as its name implies - is just a Context object. It's used during transition by your animator object (which implements either UIViewControllerAnimatorTransitioning or UIViewControllerInteractiveTransitioning).

This context object gives you access to your viewControllers' views, that you can manipulate, animate, ... and you use it to report transition progress (e.g. : you do an animation of frames and opacity, and then tell the transition context to complete...)

EDIT

Here is another SO Post where I gave some hints on how these APIs work -> IOS 7 Weather APP Like Transition/Animations

Upvotes: 1

Nitesh Kumar Singh
Nitesh Kumar Singh

Reputation: 143

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewControllerTransitioningDelegate_protocol

An object that implements the UIViewControllerTransitioningDelegate protocol vends the objects used to manage a fixed-length or interactive transition between view controllers. When you want to present a view controller using a custom modal presentation type, set its modalTransitionStyle property to UIModalPresentationCustom and assign an object that conforms to this protocol to its transitioningDelegate property. When you present that view controller, UIKit queries your transitioning delegate for the objects to use when animating the view controller into position.

https://developer.apple.com/library/tvos/documentation/UIKit/Reference/UIViewControllerContextTransitioning_protocol/index.html

The UIViewControllerContextTransitioning protocol’s methods provide contextual information for transition animations between view controllers. Do not adopt this protocol in your own classes, nor should you directly create objects that adopt this protocol. During a transition, the animator objects involved in that transition receive a fully configured context object from UIKit. Custom animator objects—objects that adopt the UIViewControllerAnimatorTransitioning or UIViewControllerInteractiveTransitioning protocol—should simply retrieve the information they need from the provided object.

Upvotes: 0

Related Questions