我需要创建具有自定义尺寸(例如:CGSize(width: 100, height: 100)
和坐标)的自定义modalVC 。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)
}
}
PS:我知道如何像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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句