本文介绍了UIViewController自定义过渡卡在iOS13上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的iOS应用中实现了两个视图控制器之间的自定义过渡,并且可以在iOS 10、11和12上正常工作.

I've implemented a custom transition between two view controllers in my iOS app and it worked fine with iOS 10, 11, and 12.

现在,我想使用Xcode 11 beta 6和iOS 13 beta 8为iOS 13做好准备,但是过渡很困难.

Now I want make it ready for iOS 13 using Xcode 11 beta 6 and iOS 13 beta 8, but the transition is stuck.

自定义过渡应将第一个视图控制器向上移动并移出屏幕,第二个视图控制器从下向上移出.但是现在,它又回到了iOS13的默认表示样式pageSheet,只是将第一个视图控制器缩小了一点,并添加了暗淡的叠加层.但是第二个视图没有出现.

The custom transition should move the first view controller up and out of the screen and the second one from bottom up. But now it falls back to iOS13 default presentation style pageSheet, just scales the first view controller down a little bit and adds a dimmed overlay. But the second view doesn't appear.

我发现在方法animatePresentation(context: UIViewControllerContextTransitioning)context不会返回'from'视图,因此context.view(forKey: .from)返回nil.

I've found that in the method animatePresentation(context: UIViewControllerContextTransitioning) the context doesn't return a 'from' view, so context.view(forKey: .from) returns nil.

如果没有'from'视图,我该怎么办?

What am I supposed to do without a 'from' view?

FlyUpTransition.swift

class FlyUpTransition: NSObject, UIViewControllerAnimatedTransitioning {

    var mode: Mode = .present

    enum Mode {
        case present
        case dismiss
    }

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return TimeInterval(0.45)
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        switch mode {
        case .present:
            animatePresentation(context: transitionContext)
        case .dismiss:
            animateDismissal(context: transitionContext)
        }
    }

    func animatePresentation(context: UIViewControllerContextTransitioning) {
        guard let fromView = context.view(forKey: .from), let toView = context.view(forKey: .to) else { return }
        ...
    }

    func animateDismissal(context: UIViewControllerContextTransitioning) {
        guard let fromView = context.view(forKey: .from), let toView = context.view(forKey: .to) else { return }
        ...
    }
}

推荐答案

好,即使这是Apple的API重大更改,也很容易.

Ok, it was easy, even though, it's a breaking API change of Apple.

viewController.modalPresentationStyle = .fullScreen

现在,我必须浏览我的整个项目,并检查所有模态演示是否仍按我的需要.

Now I have to go through my whole project and check all modal presentations if they still look as I need them to.

这篇关于UIViewController自定义过渡卡在iOS13上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 05:10