gpt4 book ai didi

ios - Swift 中的弹出 View

转载 作者:搜寻专家 更新时间:2023-10-31 21:59:07 24 4
gpt4 key购买 nike

我有一个弹出 View (没有标签栏),它被弹出到带有标签栏的 View Controller 。在带有选项卡栏的 View Controller 中,我设置了一个单击按钮,以便弹出 View Controller :

  @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 View Controller 中,我对弹出窗口进行了动画处理。

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

但是当出现弹出窗口时,所有内容都有一个褪色的黑色背景,我想要这样,除了标签栏。我希望 View 上方的弹出框也可以弹出标签栏,并且褪色的黑色背景可以覆盖它。

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

黑色褪色背景覆盖标签栏

最佳答案

发生这种情况是因为您必须将弹出窗口显示为模态 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)
}

关于ios - Swift 中的弹出 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44709096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com