我需要创建具有自定义大小的自定义modalVC(例如:CGSize(width: 100, height: 100)
和坐标)。 ModalVC可能不像popover(popover有圆角)。
将出现带有“Done”项的导航栏,用于关闭此modalVC。
VC将为其他VC中的UIButton创建。
有我的代码(由其他代码创建,只有popover存在):
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)