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

将有一个导航栏,其中包含“Done”项,用于关闭此modalVC。

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

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

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:我知道如何像PopOver这样来做,但不像自定义模式那样。

最佳答案

尝试这个

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)

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

关于ios - 如何使用navBar和自定义大小创建modalVC?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49067471/

10-11 00:33
查看更多