在Swift 4.2中完成动画后无法删除UIImage

时间:2018-08-02 00:59:59

标签: ios swift

我在应用程序中设置了自定义过渡动画(Swift 4.2)。用户触摸UICollection Cell,该单元格具有图像(低分辨率)。当触摸该单元格时,该单元格图像将展开为全屏。最后,我删除该图像并显示其他视图控制器。但是该图像视图可以删除第一次。但是无法再次移除。当我再次触摸电池时,我必须等待很长时间才能移除图像,为什么?

 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!!!")


    }
}

0 个答案:

没有答案