如何解决自定义过渡覆盖状态栏
我在做一个控制器的自定义动画,我想让控制器的黑色背景(dimmView)覆盖状态栏,我尝试了很多选项但我所有的搜索都没有结果,项目可以从link
UIViewControllerTransitioningDelegate
class PanelTransition: NSObject,UIViewControllerTransitioningDelegate {
private let driver = TransitionDriver()
func presentationController(forPresented presented: UIViewController,presenting: UIViewController?,source: UIViewController) -> UIPresentationController? {
driver.link(to: presented)
let presentationController = DimmPresentationController(presentedViewController: presented,presenting: presenting ?? source)
presentationController.driver = driver
return presentationController
}
func animationController(forPresented presented: UIViewController,presenting: UIViewController,source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return PresentAnimation()
}
func animationController(fordismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return dismissAnimation()
}
func interactionControllerFordismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return driver
}
func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return driver
}
}
PresentationController 子类 UIPresentationController
class DimmPresentationController: PresentationController{
private lazy var dimmView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(white: 0,alpha: 0.3)
view.alpha = 0
return view
}()
override func containerViewDidLayoutSubviews() {
super.containerViewDidLayoutSubviews()
dimmView.frame = containerView!.frame
}
override func presentationTransitionWillBegin() {
super.presentationTransitionWillBegin()
containerView?.insertSubview(dimmView,at: 0)
performAlongsideTransitionIfPossible { [uNowned self] in
self.dimmView.alpha = 1
}
}
override func presentationTransitionDidEnd(_ completed: Bool) {
super.presentationTransitionDidEnd(completed)
if !completed {
self.dimmView.removeFromSuperview()
}
}
override func dismissalTransitionWillBegin() {
super.dismissalTransitionWillBegin()
performAlongsideTransitionIfPossible { [uNowned self] in
self.dimmView.alpha = 0
}
}
override func dismissalTransitionDidEnd(_ completed: Bool) {
super.dismissalTransitionDidEnd(completed)
if completed {
self.dimmView.removeFromSuperview()
}
}
private func performAlongsideTransitionIfPossible(_ block: @escaping () -> Void) {
guard let coordinator = self.presentedViewController.transitionCoordinator else {
block()
return
}
coordinator.animate(alongsideTransition: { (_) in
block()
},completion: nil)
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。