导航控制器,pushViewController 的转场动画
与 ViewController 的 present 转场动画不同
1, 导航控制器,pushViewController 的转场动画,的代理是
navigationController?.delegate = self
【导航控制器,pushViewController 的转场动画】2, 指定动画的方法
extension Two: UINavigationControllerDelegate{func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == .push{
return navAnimatorPush
}
else{
return nil
}
}}
具体的动画设置也不同
使用
snapshotView
, 会出现奇怪的效果代码很好理解
class NavBaseCustomAnimatorPush: NSObject, UIViewControllerAnimatedTransitioning{func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 1
}func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {guard let fromCtrl = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from),
let toCtrl = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to), let fromView = fromCtrl.view, let toView = toCtrl.view else{
return
}let containerView = transitionContext.containerView
let f = UIScreen.main.boundsfromView.frame = fcontainerView.addSubview(fromView)
containerView.addSubview(toView)toView.frame = presentingDirection.offsetF(withFrame: f)UIView.animate(withDuration: transitionDuration(using: transitionContext), delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: .curveLinear) {
toView.frame = f
} completion: { _ in
let success = !transitionContext.transitionWasCancelled
transitionContext.completeTransition(success)
}
}}
github repo
推荐阅读
- IDEA|IDEA 创建工程
- 移动用户体验设计(底部导航)
- EXCEL的汽车导航-全能的GPS定位
- React|React Native创建TabBar和导航栏
- 解决edge 每次启动 都会新开一个360网址导航页
- 导航栏设置
- iOS|iOS 导航栏返回的奇怪上移动画的bug
- Flutter实现左侧边栏导航
- 基于Vue实现的侧边栏导航组件,自动居中,上下滑动切换菜单
- 为了实践微前端,重构了自己的导航网站