在Swift中弹出视图

时间:2017-06-22 20:46:41

标签: ios swift

我有一个弹出视图(没有标签栏),弹出到带有标签栏的视图控制器。在带有标签栏的视图控制器中,我设置了一个单击按钮,以便弹出视图控制器:

  @IBAction func PopUpClicked(_ sender: UIButton) -> Void {

        let popOverVC = UIStoryboard(name: "SpinningWheel", bundle: nil).instantiateViewController(withIdentifier: "PhotoPopUp") as! PopUpViewController

        self.addChildViewController(popOverVC)

        popOverVC.view.frame = self.view.frame
        self.view.addSubview(popOverVC.view)
        popOverVC.didMove(toParentViewController: self)
    }

在popOver视图控制器中,我为弹出窗口设置了动画。

override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.black.withAlphaComponent(0.8)


        self.showAnimate()

        // Do any additional setup after loading the view.
    }


      func showAnimate()
        {
            self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
            self.view.alpha = 0.0;
            UIView.animate(withDuration: 0.25, animations: {
                self.view.alpha = 1.0
                self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)

            });
        }

        func removeAnimate()
        {
            UIView.animate(withDuration: 0.25, animations: {
                self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
                self.view.alpha = 0.0;

            }, completion:{(finished : Bool)  in
                if (finished)
                {
                    self.view.removeFromSuperview()
                }
            });
        }

但是当popover发生时,Everything有一个褪色的黑色背景,除了标签栏我想要它。我希望Pop上的Pop也可以弹出tabbar,褪色的黑色背景也可以覆盖它。

这就是我想要的样子: enter image description here

黑色褪色背景覆盖标签栏

2 个答案:

答案 0 :(得分:6)

这种情况发生了,因为你必须将你的popover呈现为模态ViewController。要实现这一点,您必须在从目标ViewController呈现弹出窗口之前设置模式演示样式。应在您的呈现ViewController中调用此代码:

let vc = YourPopOverViewController(nib: UINib(name: "PopOverViewController", bundle: nil), bundle: nil)
vc.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext

tabBarController.present(vc, animated: true)

编辑:

如果您将PopOverViewController设计为全屏ViewController,这应该可以解决问题。我已经做了很多次,并且留下了不应该作为明确背景呈现的空间:

@IBAction func PopUpClicked(_ sender: UIButton) -> Void {
    let popOverVC = UIStoryboard(name: "SpinningWheel", bundle: nil).instantiateViewController(withIdentifier: "PhotoPopUp") as! PopUpViewController
    popOverVc.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
    tabBarController.present(popOverVC, animated: true)
}

答案 1 :(得分:1)

此第三方EzPopup可以轻松解决问题:https://github.com/huynguyencong/EzPopup

%26