简体   繁体   English

PushViewController() 导致弹出框全屏

[英]PushViewController() causes popover to be full screen

I want to push a popover on top of my view controller.我想在我的视图控制器上推送一个弹出框。 Currently, this code resides in my subclass of UIView :目前,此代码位于我的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)
    }

This is my class declaration:这是我的类声明:

class GridView: UIView, ModalHandler, UIPopoverPresentationControllerDelegate {

I have these two methods as well:我也有这两种方法:

func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
    return false
}

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.none
}

In the storyboard, for the view controller I want to be a popover, I set the content size( this and this ).在故事板中,对于我想成为弹出框的视图控制器,我设置了内容大小( thisthis )。

However, when the popover is shown, it is shown full screen.但是,当显示弹出窗口时,它会全屏显示。 When I previously used popovers, I would present them.当我以前使用 popovers 时,我会展示它们。 Does popover display not work using pushViewController() ?使用pushViewController()不能显示弹出窗口吗?

The animation is quite complicated if you have little experience.如果你没有什么经验,动画是相当复杂的。 The following code may give you some clues.下面的代码可能会给你一些线索。

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM