gpt4 book ai didi

ios - 黑屏出现在呈现的 View Controller 下方

转载 作者:搜寻专家 更新时间:2023-11-01 06:27:23 26 4
gpt4 key购买 nike

我正在尝试以模态方式呈现 View Controller 。它就像一个弹出 View Controller 。

我正在使用 animateTransition 方法为过渡设置动画。这是我的代码:

extension PopUpViewController: UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning {

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.25
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

guard let fromVC = transitionContext.viewController(forKey: .from) else { return}
guard let toVC = transitionContext.viewController(forKey: .to) else { return}
guard let fromView = transitionContext.view(forKey: .from) else { return}
guard let toView = transitionContext.view(forKey: .to) else { return}

var containerView = transitionContext.containerView

if toVC == self {
// presenting
containerView.addSubview(toView)
toView.frame = fromView.frame
popUpView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
toView.alpha = 0
UIView.animate(withDuration: 0.25, animations: {
toView.alpha = 1
self.popUpView.transform = CGAffineTransform.identity
}) { _ in

DispatchQueue.main.async {
transitionContext.completeTransition(true)
}
}
} else {
// dismissing
UIView.animate(withDuration: 0.25, animations: {
self.popUpView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
fromView.alpha = 0
}) { _ in
transitionContext.completeTransition(true)
}
}
}

func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}
}

我以这种方式在另一个 View Controller (Presenting VC)上呈现这个 View Controller (Presented VC)。我正在使用默认的模态呈现样式。最初我使用的是自定义,但我查看了 StackOverflow 上的一些帖子,他们说要删除它,但我仍然遇到黑屏(显示 VC)并且我可以在上面看到显示的 VC。

当我关闭呈现的 VC 时,呈现的 VC 再次可见。

如果您需要更多详细信息,请告诉我。

根据transitionContext.completeTransition(true)执行时的代码,呈现VC屏幕变黑

最佳答案

您可以尝试将弹出 View Controller 的 modalPresentationStyle 设置为 .overCurrentContext.overFullScreen

case overCurrentContext:

A presentation style where the content is displayed over another view controller’s content.

这意味着它将在 viewController 的内容上显示下一个 viewController。

所以对于 Container ViewControllers:

因此,如果您有任何 tabBarControllertabBar 将允许用户与之交互。

case overFullScreen

A view presentation style in which the presented view covers the screen.

这意味着它将在全屏上呈现下一个 viewController,因此 taBar 在呈现完成之前不会交互。

func presentNextController() {
// In case your viewController is in storyboard or any other initialisation
guard let nextVC = storyboard.instantiateViewController(with: "nextVC") as? NextViewController else { return }

nextVC.modalPresentationStyle = .overFullScreen
// set your custom transitioning delegate

self.present(nextVC, animated: true, completion: nil)
}

关于ios - 黑屏出现在呈现的 View Controller 下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52345878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com