如何使用 navBar 和自定义大小创建 modalVC?

How create modalVC with navBar and custom size?

我需要创建具有自定义尺寸(例如:CGSize(width: 100, height: 100) 和坐标)的自定义模态VC。 ModalVC 可能不像 popover(popover 有圆角)。

将有一个带有项目 "Done" 的导航栏,用于关闭此模式VC。

VC 将为按下其他 VC 中的 UIButton 创建。

这是我的代码(由其他代码创建,仅存在弹出窗口):

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
    @IBOutlet var button: UIButton!
    @IBAction func buttonPressed(sender: UIButton) {
        showModalVC()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func showModalVC() {
        let modalVC = CustomModalViewController()
        modalVC.modalPresentationStyle = .popover
        if let modal = modalVC.popoverPresentationController {
            modal.delegate = self
            modal.sourceView = self.view
        }
        self.present(modalVC, animated: true, completion: nil)
    }
}

class CustomModalViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.preferredContentSize = CGSize(width: UIScreen.main.bounds.width,
                                           height: UIScreen.main.bounds.height/3)
    }
}

P.S: I know how to do this like PopOver, but not like custom modal.

试试这个

let VC = self.storyboard!.instantiateViewController(withIdentifier: "Identifier") as! YourViewController
let navController = UINavigationController(rootViewController: VC)
navController.preferredContentSize = CGSize(width: 500, height: 400)
navController.modalPresentationStyle = .formSheet
self.present(navController, animated:true, completion: nil)