Difference between UIViewControllerTransitioningDelegate and UIViewControllerContextTransitioning - ios

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!

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

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.

Related

How do you use UIViewControllerTransitionCoordinator?

The documentation of UIViewControllerTransitionCoordinator isn't very detailed. It implies that you may want to implement this protocol in rare circumstances, but UIViewControllerTransitionCoordinator implements UIViewControllerTransitionCoordinatorContext, which means that you have to implement over a dozen(!) methods to conform to the protocol. I've seen some other people using it by accessing the transitionCoordinator property of a UIViewController while it is being presented, usually in viewWillAppear. However, the documentation implies that viewWillAppear is not the right place to implement either. How are you supposed to make use of this protocol and synchronize animations with those of a presenting view?

Segues vs. UIViewControllerAnimatedTransitioning

While searching how to perform custom animations when transitioning from one controller to another I found some info about UIViewControllerAnimatedTransitioning.
So the question is: why do we even need this if we have custom segues? Are they interchangeable or not? If yes, why does Apple provide two ways of doing the same task?
Some differences:
Segues can only be used with storyboards.
Animator objects can be used programmatically, or along with segues.
Animator objects allow you to set a customized final position and size for your new view controller.
Animator objects can be configured to do special animations with navigation controllers and collection views.
Animator objects also allow interactive transitions using UIViewControllerInteractiveTransitioning, which segues don't.

iOS subview custom transition

When presenting a UIViewController that implements UIViewControllerTransitioningDelegate it is easily possible to customize the viewtransition.
Now I would like to know if I can customize a viewtransition for a subview? Lets say I have a tapable tile that currently flips when tapped (UIViewAnimationOptionTransitionFlipFromRight). Although that is a very nice effect I rather would like to customize this transition. But I do not know how to start..
To clarify I would like to use an AnimationController<UIViewControllerAnimatedTransitioning> to handle my subviewtransition - is that possible?
Any suggestions?
Well this is not possible out of the box but there are some ways to achieve that but this will need some deeper knowledge of how the custom transition are working in detail.
Here are two articles describing what you are looking for in detail:
Custom Container View Controller Transitions
http://www.objc.io/issue-12/custom-container-view-controller-transitions.html
Interactive Custom Container View Controller Transitions
http://www.iosnomad.com/blog/2014/5/12/interactive-custom-container-view-controller-transitions
Answering with regards to your comment : you cannot.
From UIViewControllerAnimatedTransitioning protocol documentation :
Adopt the UIViewControllerAnimatedTransitioning protocol in objects that implement the animations for a custom view controller transition. The methods in this protocol let you define an animator object, which creates the animations for transitioning a view controller on or off screen in a fixed amount of time.
This protocol is only for UIViewControllers (and its descendants), and UIView doesn't inherit from it.

Send the value in Class of ViewController to Class of View

Is there any way that could send the value in Class of ViewController to Class of View?
Because I want to make a drawing board and I made a modal scene to set values about color, width .
I know how to send the value in modal scene to my ViewController , but now I need use those value in Class of View , or not Class of ViewController.
Sounds like you need to devise a protocol to open a delegation channel between the two classes. Then when the modal VC wants to send data to its delegate (its presenter, in this case), it can of its own volition.
The View Controller can have a reference to the View, therefore the View Controller can simply pass the values to View by calling a View's method or updating View's properties. This is a common pattern: View defines a Protocol and data/requests from View to ViewController go through this Protocol (the ViewController acts as delegate of View); and ViewController owns the View.
For inspiration on how to implement a farily decoupled design applying this pattern, you can have a look at documentation on UICollectionView and UICollectionViewController.
Other options, depending on what design you need, are Key-Value Observing or Notifications.

How to implement interactive transitions in a custom container view controller

I implemented my own custom container view controller and I try to make it compatible with iOS 7 view controller transitions. I make my custom container view controller conform to UIViewControllerContextTransitioning and I send self when I call transitionDuration: and animateTransition:. It all works fine as long as I use only animated transitions.
Now I want to make it work with interactive transitions, so I call the interaction controller's startInteractiveTransition: instead of the animation controller's animateTransition:, using self again as a parameter. However, if I use a UIPercentDrivenInteractiveTransition as the interaction controller, it then calls a _animator method on my context (which is the container view controller itself). Of course, I haven't implemented this method which is private and undocumented, so it crashes...
Am I missing something in my implementation? Is UIPercentDrivenInteractiveTransition only compatible with Apple classes because it uses some implementation magic (as when it requires that everything should be in a UIView animation block)? The documentation and header files make it look like we can implement our own container view controllers and still use custom transitions, but is it really true or just wishful thinking because nobody would actually do that?
If I can't use UIPercentDrivenInteractiveTransition, then where exactly should the interaction/animation logic be? In the UIViewControllerTransitionCoordinatorContext object? In the UIViewControllerInteractiveTransitioning object (most likely, this object is the driver...)? Or in the UIViewControllerAnimatedTransitioning object (this is probably where the real animation should happen, but would that mean calling animateTransition: several times during the interaction? Or adding new methods for each step of the interactive transition?)
Edit: The documentation says:
A percent-driven interactive transition object drives the custom animation between the disappearance of one view controller and the appearance of another. It relies on a transition animator delegate—a custom object that adopts the UIViewControllerAnimatorTransitioning protocol—to set up and perform the animations.
There is no UIViewControllerAnimatorTransitioning protocol. Assuming it is a mistake, or a name change that happened during iOS 7 development and it is actually the UIViewControllerAnimatedTransitioning protocol, how do we link the interaction controller with the animation controller? I guess it's the responsibility of the view controller driving the transition but I don't see any API to make this link, so it would mean that UIPercentDrivenInteractiveTransition is indeed reserved for Apple classes?
I'm trying to do the same on my own and ended up writing my own UIPercentDrivenInteractiveTransition equivalent. Seems like the percent driven transition asks for the animation and actually starts it after the interactive transition is started. I've got some trouble with implementing the reverse animation when canceling though.

Resources