【发布时间】:2018-09-24 08:21:37
【问题描述】:
我想在我的视图控制器顶部推送一个弹出框。目前,此代码位于我的UIView 子类中:
func presentGameOver() {
let transition: CATransition = CATransition()
transition.duration = 0.75
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.fade
let currentController = (getCurrentViewController() as! UINavigationController).topViewController!
currentController.navigationController!.view.layer.add(transition, forKey: nil)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "GameOverViewController") as! GameOverViewController
vc.modalPresentationStyle = UIModalPresentationStyle.popover
vc.highScore = highScore
vc.score = score
vc.FONT_H = FONT_H
vc.delegate = self
currentController.navigationController?.pushViewController(vc, animated: false)
}
这是我的班级声明:
class GridView: UIView, ModalHandler, UIPopoverPresentationControllerDelegate {
我也有这两种方法:
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return false
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
在情节提要中,对于我想成为弹出框的视图控制器,我设置了内容大小(this 和 this)。
但是,当显示弹出框时,它会全屏显示。当我以前使用弹出框时,我会展示它们。使用pushViewController() 是否无法显示弹出框?
【问题讨论】:
-
pushViewController不显示弹出框,它将视图推送到导航控制器上。使用present,而不是pushViewController。 -
@rmaddy 感谢您的快速回复!我将代码更改为
currentController.present(vc, animated: false, completion: nil),但我似乎仍然得到相同的结果。有什么想法吗? -
通常情况下,
popover仅适用于 iPad。它在 iPhone 上是全屏的。 (不过有一些方法可以解决。)此外,通常“游戏结束”弹出窗口是UIAlertController。在这两点上,关键词都是“典型地”。