iOS push出present类似的模态效果

2024-02-26  本文已影响0人  可乐小子

func popVcCustomAnimation(_ viewController: UIViewController? = nil) {
let vc = viewController == nil ? self:viewController
let animation = CATransition()
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
animation.type = .fade
animation.duration = 0.3
vc?.navigationController?.view.layer.add(animation, forKey: nil)
vc?.navigationController?.popViewController(animated: false)
}

func popRootVcCustomAnimation(_ viewController: UIViewController? = nil) {
    let vc = viewController == nil ? self:viewController
    let animation = CATransition()
    animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
    animation.type = .fade
    animation.duration = 0.3
    vc?.navigationController?.view.layer.add(animation, forKey: nil)
    vc?.navigationController?.popToRootViewController(animated: false)
}

func pushVcCustomAnimation(_ viewController: UIViewController) {
    navigationController?.pushViewController(viewController, animated: false)
    let animation = CATransition()
    animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
    animation.type = .fade
    animation.duration = 0.3
    navigationController?.view.layer.add(animation, forKey: nil)
}
上一篇下一篇

猜你喜欢

热点阅读