如何将ViewController呈现为没有背景阴影的模态表



是否有任何方法来呈现ViewController作为一个模态表没有背景阴影,如下图所示,使用swift。是否有一个简单的方法或者我们需要写自定义UIPresentationController?[![所需输出][1]][1]

[1]: https://i.stack.imgur.com/QAEEn.png ![输入图片描述](https://i.stack.imgur.com/q4JD5.jpg)

您可以根据需要使用较小的视图控制器。首先添加一个类。

class SmallSizePresentationController : UIPresentationController {
override var frameOfPresentedViewInContainerView: CGRect {
get {
guard let theView = containerView else {
return CGRect.zero
}
return CGRect(x: 0, y: theView.bounds.height * (281 / 896), width: theView.bounds.width, height: theView.bounds.height)
}
}
}

然后当你想要呈现这种类型的视图控制器时,只需添加当前视图控制器的扩展。

extension YourCurrentViewController: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return SmallSizePresentationController(presentedViewController: presented, presenting: presenting)
}
}

然后像这样呈现你的新视图控制器

let VC = withoutShadowVC()
VC.transitioningDelegate = self
VC.modalPresentationStyle = .custom
self.present(VC, animated: true, completion: nil)

你可以修改视图控制器的高度

最新更新