答案 0 :(得分:0)
我解决了我的问题。 我将仅对iOS 12使用自定义过渡。
我的动画代码的一部分(用于演示)
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let container = transitionContext.containerView
let fromController = transitionContext.viewController(forKey: .from)!
let toController = transitionContext.viewController(forKey: .to)!
let originalFrame = transitionContext.finalFrame(for: toController)
let toView = transitionContext.view(forKey: .to)!
let fromView = transitionContext.viewController(forKey: .from)!
container.addSubview(toView)
let offset = SlideTransitionHelper.offset(controllerSize: originalFrame.size)
toView.frame = originalFrame.offsetBy(dx: offset.x, dy: offset.y)
let scale: CGFloat = UIApplication.shared.statusBarFrame.height == 20 ? 0.93 : 0.91
UIView.animate(
withDuration: self.transitionDuration(using: transitionContext),
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0.4,
options: .allowUserInteraction,
animations: {
toView.frame = originalFrame
toView.roundCorners([.topLeft, .topRight], radius: 12)
toView.layer.masksToBounds = true
if let tabBarController = fromController as? UITabBarController {
if let activeController = tabBarController.selectedViewController as? UINavigationController, let childController = activeController.children.first{
//Animate NavigationBar color
childController.navigationController?.navigationBar.barTintColor = self.themeManager.current.systemSecondaryColor
childController.navigationController?.navigationBar.layoutIfNeeded()
//Animate controller background color
childController.view.backgroundColor = self.themeManager.current.systemSecondaryColor
}
}
//Scale controller
var transform = CATransform3DIdentity
transform = CATransform3DScale(transform, scale, scale, 1.0)
transform = CATransform3DTranslate(transform, 0, scale, 0)
fromView.view.layer.transform = transform
fromView.view.layer.cornerRadius = 12
fromView.view.layer.masksToBounds = true
},
completion: { (isFinished) in
transitionContext.completeTransition(isFinished)
})
}