轻按imageView时,如何隐藏导航栏;轻按imageView时,导航栏会弄乱全屏图像的视图;我想在轻按图像时将其隐藏,并在关闭图像后重新显示。这是我的图像被窃取的代码。

//expandImage




@IBAction func expand(_ sender: UITapGestureRecognizer) {
    let imageView = sender.view as! UIImageView
    let newImageView = UIImageView(image: imageView.image)
    newImageView.frame = self.view.frame
    newImageView.backgroundColor = .black
    newImageView.contentMode = .scaleAspectFit
    newImageView.isUserInteractionEnabled = true
    let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreen))
    newImageView.addGestureRecognizer(tap)
    self.view.addSubview(newImageView)
}

func dismissFullscreen(_ sender: UITapGestureRecognizer) {
    sender.view?.removeFromSuperview()
}

最佳答案

将此添加到您的expand()方法中:

self.navigationController?.setNavigationBarHidden(true, animated: true)

在dismissFullscreen()方法中:
self.navigationController?.setNavigationBarHidden(false, animated: true)

或者,您可以创建新的ViewController,将图像传递给它(例如segue),然后将其添加到新ViewController的viewDidLoad()中:
self.navigationController?.hidesBarsOnTap = true

10-08 05:45