swift - animateTransition 不再适用于 iOS 13 中以模态呈现的 vie

当用户在 tableViewController 的单元格中选择 imageView 到显示放大图像的焦点 View 时,我一直在我的自定义 Animator 类中使用以下方法进行转换。 imageView 很好地从它在 tableView 中的框架动画到全屏,然后在我关闭它时返回。

这在 iOS 13 之前工作正常。但是现在当我在模态呈现的 tableViewController 上使用这个动画转换时,焦点 View 的动画效果很好但是当我关闭焦点 View 以动画回到 tableViewController 时,tableViewController 是不再存在。它只显示了在模态呈现的 tableViewController 下方的灰色 viewController。我知道新的 modalPresentation 默认样式是 pageSheet 但不确定为什么动画之前的顶 View Controller 消失了?

动画对于未模态呈现的 viewController 仍然可以正常工作。

想知道这是一个错误还是有人找到了解决方案?

这是我的 animateTransition 函数:

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    // define variable to keep track of whether transitioning from or to
    var presentingImage = false

    // define containerView
    let containerView = transitionContext.containerView

    // get view controllers
    let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
    let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!

    // set the destination view controllers frame
    toVC.view.frame = fromVC.view.frame

    // create transition imageView
    let imageView = UIImageView(image: image)
    imageView.contentMode = .scaleAspectFill
    imageView.frame = (fromDelegate == nil) ? CGRect() : fromDelegate!.imageWindowFrame()
    imageView.clipsToBounds = true

    // add imageView to containerView
    containerView.addSubview(imageView)

    // create from screen snapshot
    fromDelegate!.transitionSetup(presentingImage: presentingImage)
    toDelegate!.transitionSetup(presentingImage: presentingImage)
    let fromSnapshot = fromVC.view.snapshotView(afterScreenUpdates: true)!
    fromSnapshot.frame = fromVC.view.frame
    containerView.addSubview(fromSnapshot)

    // create to screen snapshot
    let toSnapshot = toVC.view.snapshotView(afterScreenUpdates: true)!
    toSnapshot.frame = fromVC.view.frame
    containerView.addSubview(toSnapshot)
    toSnapshot.alpha = 0

    // bring the image view to the front and get the final frame
    containerView.bringSubviewToFront(imageView)
    let toFrame = (self.toDelegate == nil) ? CGRect() : self.toDelegate!.imageWindowFrame()

    // animate change
    UIView.animate(withDuration: transitionDuration(using: transitionContext), delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: .curveEaseOut, animations: {

        // set toSnapshot alpha to 1
        toSnapshot.alpha = 1

        // set imageView frame to toFrame
        imageView.frame = toFrame

    }, completion:{ (finished) in

        // call transition cleanup for to and from delegate
        self.toDelegate!.transitionCleanup(presentingImage: presentingImage)
        self.fromDelegate!.transitionCleanup(presentingImage: presentingImage)

        // remove transition views
        imageView.removeFromSuperview()
        fromSnapshot.removeFromSuperview()
        toSnapshot.removeFromSuperview()

        // complete transition
        if !transitionContext.transitionWasCancelled {
            containerView.addSubview(toVC.view)
        }
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    })
}

最佳答案

上面的答案是将 modalPresentationStyle 设置为 .fullScreen 是正确的,但是还值得一提的是,如果您的 View Controller 嵌入在 UINavigationController 中,则需要在 View Controller 上进行设置:

viewController.modalPresentationStyle = .fullScreen

关于swift - animateTransition 不再适用于 iOS 13 中以模态呈现的 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58248687/

相关文章:

asp.net-core-webapi - .NET Core 3 API - 在一个请求后停止工作

objective-c - 无法编译使用 Objective-C 包的 Swift 包

r - 在 R 中使用 RCurl 下载 NASA 卫星数据

aws-lambda - 如何使用 CloudFormation 添加订阅过滤器?

python - TensorFlow 的可微分汉明损失

reactjs - React Native - SetTimeout() 不工作。 t.apply

angular - 运行 karma 测试时出现错误无法读取 null 的属性 'extras'

c# - 是否可以动态更改 ToolbarItem 的图标?

angular - Ionic Barcode Scanner 插件关闭按钮

r - R : how to find the place of maximum memory us