- 在Storyboard中新建一个ViewController命名为MyDialogViewController,将背景色设置为黑色半透明(使对话框的背景变暗),新建一个View居中显示用来放置对话框内容。
- 弹出MyDialogViewController前将其modalPresentationStyle设置为UIModalPresentationStyle.overFullScreen。
private func showDialog(){
let storyboard=UIStoryboard(name: "Main", bundle: nil)
let viewController=storyboard.instantiateViewController(withIdentifier: "MyDialogViewController")
viewController.modalPresentationStyle=UIModalPresentationStyle.overFullScreen
present(viewController,animated: false, completion: nil)
}