PushViewController() 导致 popover 全屏
PushViewController() causes popover to be full screen
我想在我的视图控制器上推送一个弹出窗口。目前,此代码位于我的 UIView
的子 class 中:
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声明:
class GridView: UIView, ModalHandler, UIPopoverPresentationControllerDelegate {
我也有这两种方法:
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return false
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
在情节提要中,对于我想成为弹出窗口的视图控制器,我设置了内容大小(this and this)。
但是,当显示弹出窗口时,它会全屏显示。当我以前使用弹出框时,我会展示它们。使用 pushViewController()
时弹出框显示不工作吗?
经验少的人看动画还是挺复杂的。下面的代码可能会给你一些线索。
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
if let popoverPresentationController = vc.popoverPresentationController{
popoverPresentationController.delegate = self;
popoverPresentationController.sourceView = self
popoverPresentationController.sourceRect = CGRect.init(x: 200, y: 200, width: 500, height: 300)}
currentController.present(vc, animated: false) {}
}
我想在我的视图控制器上推送一个弹出窗口。目前,此代码位于我的 UIView
的子 class 中:
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声明:
class GridView: UIView, ModalHandler, UIPopoverPresentationControllerDelegate {
我也有这两种方法:
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return false
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
在情节提要中,对于我想成为弹出窗口的视图控制器,我设置了内容大小(this and this)。
但是,当显示弹出窗口时,它会全屏显示。当我以前使用弹出框时,我会展示它们。使用 pushViewController()
时弹出框显示不工作吗?
经验少的人看动画还是挺复杂的。下面的代码可能会给你一些线索。
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
if let popoverPresentationController = vc.popoverPresentationController{
popoverPresentationController.delegate = self;
popoverPresentationController.sourceView = self
popoverPresentationController.sourceRect = CGRect.init(x: 200, y: 200, width: 500, height: 300)}
currentController.present(vc, animated: false) {}
}