UIViewControllerAnimatedTransitioning completion block slowed down by 100x instead of 10x using "Slow Animations" in simulator

Hello,


The triggering of the UIView animation completion block following code ends up being slowed down by ~100x instead of ~10x with slow animations enabled in the simulator:


import UIKit

class Animator: NSObject, UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 0.175
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        guard let toViewController = transitionContext.viewController(forKey: .to) else {
            fatalError("to view controller not found")
        }

        transitionContext.containerView.addSubview(toViewController.view)

        toViewController.view.frame = transitionContext.containerView.frame
        toViewController.view.alpha = 0
        toViewController.view.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)

        let start = Date()

        UIView.animate(
            withDuration: transitionDuration(using: transitionContext),
            animations: {
                toViewController.view.alpha = 1
                toViewController.view.transform = .identity
        },
            completion: { finished in
                print("animateTransition completion after \(-start.timeIntervalSinceNow)")
                transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
        })
    }
}


This results in views not being interactive for a long while when developing with slow transitions on. Completion blocks to calls to UIView animations outside of animateTransition(using transitionContext: UIViewControllerContextTransitioning) are called when expected.


Does anyone know why this is?

Replies

How does it work on device ? Simulator is not always realistic as for performance.


However, have you selected release Mode instead of debug ?