Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom transition animation unknown delay between animationControllerForPresentedController and animateTransition

My aim is to make smooth animation started in the first view controller and end in the second view controller.

I'm experimenting with transition animation using object that conform to UIViewControllerAnimatedTransitioning and UIViewControllerTransitioningDelegate protocols. I set up two view controllers (VC) in the storyboard and connect them with segue (default show). I also made unwind segue method in the first VC and set up a button for it in the second VC.

I have strange problem. My object have methods

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {

    self.presenting = true
    NSLog("start")
    return self
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
    if presenting {
        NSLog("Animation Push")
        transitionPush(transitionContext)

    }
    else {
        NSLog("Animation Pop")
        transitionPop(transitionContext)

    }
}

I have two different methods for animation from first VC to second and from second to first VC. When I activate segue I have very strange delay between animationControllerForPresentedController and animateTransition methods. Sometimes it can be about 1 second, and my whole transition animation must be 1 second plus this unexpected delay is too big. Here is a log:

2015-02-08 19:52:33.528 MyApp[1318:119598] start
2015-02-08 19:52:33.979 MyApp[1318:119598] Animation Push

I don't know why this delay occur and if there a way to remove or reduce it? I tried to check if this could be my code, but I didn't find any prove of it. Feel free to ask for more info.

like image 572
Dima Deplov Avatar asked Feb 08 '15 17:02

Dima Deplov


People also ask

Do I need modalpresentationstyle=”custom” for transition animations?

Custom transition animations don’t require modalPresentationStyle = .custom unless the presentation itself needs to be customized, not just the transition. (Just remember to add the to view controller’s view to the transition context)

How to create a custom dismiss animation controller in uiviewcontrollertransitioningdelegate?

The UIViewControllerTransitioningDelegate also allows you to specify an animation controller to use when dismissing a view controller as well as when presenting one. We’ll create this next. Create a class named CustomDismissAnimationController that is a subclass of NSObject. Modify its declaration as shown. Add the following to the class.

What is the duration of the animation used in the transition?

The duration of the animation used is the one set in transitionDuration (transitionContext:). In the completion closure, we notify the transition context when the animation completes and then change the from view ‘s alpha back to normal. The framework will then remove the from view from the container.

How to use the animation controller with a view controller?

This class is referred to as the animation controller. Before presenting a view controller, set a class as its transitioning delegate. The delegate will get a callback for the animation controller to be used when presenting the view controller. Implement the callback method to return an instance of the animation controller from the first step.


2 Answers

I found solution (workaround) in discussion here, author – tamas.zahola

[self presentViewController:myViewController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{}); // <--- this line
like image 111
Sound Blaster Avatar answered Sep 28 '22 11:09

Sound Blaster


I've experienced this too. In my case I was seeing a 0.7s delay between the time I pushed a view controller with a custom animation transition and the time the animateTransition(using transitionContext:) method was called. The delay was highly perceptible to the end user.

The problem as it turns out was that the view controller I was pushing was loading some large images from the Asset Catalog on the main thread.

Preloading the images solved my problem.

like image 38
par Avatar answered Sep 28 '22 13:09

par