更新时间:2023-10-24 20:15:52
你可以这样做:
在你的主视图控制器中:
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .overCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
在你的模态视图控制器:
class ModalViewController: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.clearColor()
view.opaque = false
}
}
如果您正在处理故事板:
只需添加一个故事板Segue与种类
设置为向模态视图控制器提供模态
d在此视图控制器上设置以下值:
Just add a Storyboard Segue with Kind
set to Present Modally
to your modal view controller and on this view controller set the following values:
as Crashalot 在他的评论中指出:确保 segue 仅使用默认
对于演示文稿
和过渡
。使用当前上下文
获取演示文稿
使模态变为黑色而不是保持透明。
As Crashalot pointed out in his comment: Make sure the segue only uses Default
for both Presentation
and Transition
. Using Current Context
for Presentation
makes the modal turn black instead of remaining transparent.