在Swift中弹出视图 [英] Pop Up View in Swift

查看:344
本文介绍了在Swift中弹出视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a popover view (without a tab bar) that is popped over to a view controller with a tab bar. In the view controller with a tab bar I set up a button to click, so that the view controller pops up:

  @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视图控制器中,我给流行音乐动画了一下。

And in the popOver view controller, i animated the pop over.

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()
                }
            });
        }

但是当弹出窗口时,一切都有褪色的黑色背景,我想要标签栏除外。我希望Pop上的Pop也可以弹出tabbar和褪色的黑色背景来覆盖它。

But when the popover happens, Everything has a faded black background, which I want except for the tab bar. I would like for the pop over View to also pop over the tabbar and for the faded black background to go over it.

这就是我想要的样子:

This is what I want it to look like:

黑色褪色背景覆盖标签栏

With the black faded background covering the tabbar

推荐答案

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

This happens, because you have to present your popover as a modal ViewController. To achieve this you have to set the modal presentation style before presenting your popover from your target ViewController. This code should be called in your presenting ViewController:

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

tabBarController.present(vc, animated: true)

编辑:

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

This should do the trick, if you habe designed your PopOverViewController as a fullscreen ViewController. I have done this a bunch of times and have left the space which should not be presented as clear background:

@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)

}

这篇关于在Swift中弹出视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆