0

在 iOS 13 中,Apple 引入了底部表单演示控制器,其演示和关闭的一部分也是为演示视图控制器的视图设置动画。

我在学习自定义视图控制器演示的同时尝试重新创建它,并通过使用顶部视图控制器的转换协调器的animate(alongsideTransition:completion)方法(下面的代码)并在该块中为演示视图控制器的视图更改设置动画来解决它。在 iOS 14 及更低版本中,这非常适合定期解雇和展开转场(就像这样),但是在 iOS 15 中,当使用展开转场时,根视图控制器的视图没有动画并且看起来像这样,而系统标准底部表仍然看起来在放松的时候很好是否有一些替代方法可以用来通过 unwind segue 解雇多个 VC?

// This is the animation performed in the animate(...) block
presenter.view.layer.transform = self.transform3D(for: presenter, completed: true)

// This is the function definition
func transform3D(for vc: UIViewController?, completed: Bool) -> CATransform3D {
        
    guard completed else { return .identity }
        
    if let vc = vc as? ScrollViewDismissable, !vc.isPresentedFullScreen {
        
        // Handles the situation when the presenting VC is not the root VC (ViewController)
        let ratio = (UIScreen.main.bounds.width - 32) / UIScreen.main.bounds.width
        let height = frameOfPresentedViewInContainerView.height
        let newHeight = height * ratio
        let translation = (height - newHeight) / 2
            
        return CATransform3D.scale(x: ratio, y: ratio, z: 1.00001).concatenating(.translation(x: 0, y: -translation - 10, z: 1.00001))
            
    } else {
        
        // Takes care of the transform for the root VC
        let fullScreenPresentationExtraHeight: CGFloat = vc is ViewController ? 0 : (20 + 16)
            
        return .scale(x: (UIScreen.main.bounds.width - 32) / UIScreen.main.bounds.width, y: (UIScreen.main.bounds.height + fullScreenPresentationExtraHeight - (newOrigin * 2)) / (UIScreen.main.bounds.height + fullScreenPresentationExtraHeight), z: 1.00001)
    }
}
4

0 回答 0