我有一个视图控制器,其中一些容器中包含导航控制器,表格视图,其他标准控制器等...
我想从其中一个容器中选择一个模态表单,该容器将进行动画处理,扩展,移动(原始内容仍显示在下面,或者我不在乎),以进行扩展。在模态表单视图中使用“相同”控制器完成过渡
我在实施它时花费了很多时间,框架的动画存在很多错误,有人可以帮助我,还是将我重定向到一个合适的文档?
这是我要执行的操作的示例,但是此代码不起作用,并且我尝试了几种动画技术(仅在动画中使用layoutIfNeed,使用CGTransformation在此处更改帧的值等...)
extension PlayersListTableViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard let superview = self.navigationController?.view else { return nil }
guard let globalFrame = superview.superview?.convert(superview.frame, to: nil) else { return nil }
transition.originFrame = globalFrame
transition.presenting = true
return transition
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return nil
}
}
class FormAnimator: NSObject, UIViewControllerAnimatedTransitioning {
let duration = 5.0
var presenting = true
var originFrame = CGRect.zero
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let toView = transitionContext.view(forKey: .to)!
let finalView = toView
let initialFrame = originFrame
let finalFrame = finalView.frame
finalView.frame.origin = initialFrame.origin
finalView.frame.size = initialFrame.size
finalView.clipsToBounds = true
containerView.addSubview(finalView)
containerView.bringSubviewToFront(finalView)
finalView.frame = finalFrame
UIView.animate(withDuration: duration, delay:0.0,
animations: {
finalView.layoutIfNeeded()
},
completion: { _ in
print(finalView.frame)
transitionContext.completeTransition(true)
}
)
}
}