【问题标题】:PushViewController() causes popover to be full screenPushViewController() 导致弹出框全屏
【发布时间】: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
}

在情节提要中,对于我想成为弹出框的视图控制器,我设置了内容大小(thisthis)。

但是,当显示弹出框时,它会全屏显示。当我以前使用弹出框时,我会展示它们。使用pushViewController() 是否无法显示弹出框?

【问题讨论】:

  • pushViewController 不显示弹出框,它将视图推送到导航控制器上。使用present,而不是pushViewController
  • @rmaddy 感谢您的快速回复!我将代码更改为currentController.present(vc, animated: false, completion: nil),但我似乎仍然得到相同的结果。有什么想法吗?
  • 通常情况下,popover 仅适用于 iPad。它在 iPhone 上是全屏的。 (不过有一些方法可以解决。)此外,通常“游戏结束”弹出窗口是UIAlertController。在这两点上,关键词都是“典型地”。

标签: ios swift uiview popover


【解决方案1】:

如果你没有什么经验,动画是相当复杂的。下面的代码可能会给你一些线索。

    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) {}

}

【讨论】:

  • 非常感谢您的回答。弹出窗口显示,但动画似乎没有淡入淡出。这可能是什么原因?谢谢。
  • 委托很简单,并不完整。您需要在委托方法中添加更多详细信息。如何翻译和如何呈现。有很多工作。你可以在那里学到很多东西
  • 另外,如果我从这一行中删除分号:popoverPresentationController.delegate = self; 并同时删除 popoverPresentationController.sourceRect = CGRect.init(x: 200, y: 200, width: 500, height: 300)} currentController.present(vc, animated: false) {} 末尾的 {},是否可以?
  • 那是您的演示代表。如果您删除它,您的转换将不起作用。你需要他们来管理你的 popover 过渡。您可能会放弃花哨的弹出框,只需使用常规的节目细节。这取决于你。
  • 我明白了,我问的是分号(;)对那条线有什么意义吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-11
  • 2015-02-05
  • 2011-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多