Q: The UIImage can not remove after animation finish in swift 4.2 I set custom transition animation in my app (Swift 4.2). User touch the UICollection Cell,The cell have image(low resolution).When touch the cell,the cell image to be expand to full screen.in the end the I remove the image and show other view controller.but the image view can remove at the first time.but fail to remove another time.when I touch the cell again ,I must wait for very long time and image remove,why?
 func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

    isPresented ? animationForPresentedView(transitionContext: transitionContext) : animationForDismissView(transitionContext: transitionContext)
}

func animationForPresentedView(transitionContext: UIViewControllerContextTransitioning){

    guard let presentDelegate = presentedDelegate , let indexPath = indexPath else{
        return
    }


    let presentedView = transitionContext.view(forKey: .to)!


    transitionContext.containerView.addSubview(presentedView)


    let startRect = presentDelegate.startRect(indexPath: indexPath)
    let imageView = presentDelegate.imageView(indexPath: indexPath)
    transitionContext.containerView.addSubview(imageView)

    imageView.frame = startRect



    presentedView.alpha = 0.0
    transitionContext.containerView.backgroundColor = UIColor.black
    UIView.animate(withDuration: transitionDuration(using: transitionContext),animations: {
        imageView.frame = presentDelegate.endRect(indexPath: indexPath)

    }) { (_) in



        imageView.removeFromSuperview()
        presentedView.alpha = 1.0 
        presentedView.layoutIfNeeded()
        transitionContext.containerView.backgroundColor = UIColor.clear

        transitionContext.completeTransition(true)

        print("animation end!!!")


    }
}

