iOS 10 - 自定义动画后黑屏

标签 ios swift animation view ios10

我有一个可以正常工作的自定义动画,只是在关闭动画结束时出现黑屏。

转换的代码是:

class FolderAnimationController: NSObject, UIViewControllerAnimatedTransitioning {

    let duration    = 5.0
    var presenting  = true
    var originFrame = CGRect.zero
    var selectedFolderCell: FolderCollectionViewCell?

    func transitionDuration(_ transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return duration
    }

    func animateTransition(_ transitionContext: UIViewControllerContextTransitioning) {

        let containerView = transitionContext.containerView()
        let toViewC = transitionContext.viewController(forKey: UITransitionContextToViewControllerKey)!
        let fromViewC = transitionContext.viewController(forKey: UITransitionContextFromViewControllerKey)!
        let folderViewC = presenting ? fromViewC as! ViewController : transitionContext.viewController(forKey: UITransitionContextToViewControllerKey) as! ViewController
        let projectViewC = presenting ? toViewC as! ProjectViewController : transitionContext.viewController(forKey: UITransitionContextFromViewControllerKey) as! ProjectViewController

        let cellView = presenting ? (folderViewC.folderCollectionView.cellForItem(at: (folderViewC.folderCollectionView.indexPathsForSelectedItems()?.first!)!) as! FolderCollectionViewCell).folderView : projectViewC.containerView
        let cellSnapshot: UIView = presenting ? cellView!.snapshotView(afterScreenUpdates: false)! : cellView!.snapshotView(afterScreenUpdates: false)!
        let cellFrame = containerView.convert(cellView!.frame, from: cellView!.superview)
        cellSnapshot.frame = cellFrame
        cellView!.isHidden = true

        toViewC.view.frame = transitionContext.finalFrame(for: toViewC)
        toViewC.view.layoutIfNeeded()
        toViewC.view.alpha = 0

        presenting ? (projectViewC.containerView.isHidden = true) : (self.selectedFolderCell!.folderView.isHidden = true)
        containerView.addSubview(toViewC.view)
        containerView.addSubview(cellSnapshot)

        UIView.animate(withDuration: duration, animations: {

            toViewC.view.alpha = 1.0

            let finalFrame = self.presenting ? projectViewC.containerView.frame : self.originFrame
            cellSnapshot.frame = finalFrame
        }) { (_) in
            self.presenting ? (projectViewC.containerView.isHidden = false) : (self.selectedFolderCell?.isHidden = false)
            cellSnapshot.removeFromSuperview()
            transitionContext.completeTransition(true)

        }

    }
}

以及调用动画的第一个 View Controller 的代码:

func animationController(forPresentedController presented: UIViewController, presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    presentAnimator.presenting = true
    presentAnimator.originFrame = openingFrame!
    presentAnimator.selectedFolderCell = selectedCell!

    return presentAnimator
}

func animationController(forDismissedController dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    presentAnimator.presenting = false

    return presentAnimator
}

最佳答案

使用 UIViewPropertyAnimator.runningPropertyAnimator 代替 UIView.animate

关于iOS 10 - 自定义动画后黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38432269/

相关文章:

ios - 从 UITableViewController 重新加载 tableView

android - 用于移动应用程序开发的云数据库中生产/开发/测试数据的单独模式

ios - UIButton 内容集 Image : EXC_BAD_ACCESS?

SwiftUI - 基于设备的自定义 TabBar 高度

javascript - 具有流畅运动的CSS动画关键帧

ios - 是否还有其他人遇到 iOS 版本 13.1.2 的 iOS 权利问题?

ios - 从 loginviewcontroller 获取用户邮箱并显示在 revealview 的标签中

ios - 使用单击的按钮通过 tableView 传递数据

ios - 在 iOS 上,如何延迟 cameraIris 动画的打开部分

javascript - jQuery Textillate.js - 如何 "reset"元素 html 并重新启动动画