我需要创建具有自定义大小(例如:CGSize(width: 100, height: 100)
和坐标)的自定义 modalVC。 ModalVC 可能不像 popover(popover 有圆角)。
将有一个带有“完成”项的导航栏,用于关闭此 modalVC。
VC 会在其他 VC 中为 UIButton pressing 创建。
这是我的代码(由其他代码创建,仅存在弹出窗口):
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)
关于ios - 如何使用 navBar 和自定义大小创建 modalVC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49067471/