添加了可点击的代码后,我的图像视图将扩展为全屏。使用UITapGestureRecognizer关闭视图后,将无法在滚动视图中滚动。
以下是显示和关闭图像视图的代码(效果很好):
@IBAction func imageTapped(_ sender: UITapGestureRecognizer) {
let imageView = sender.view as! UIImageView
let newImageView = UIImageView(image: imageView.image)
newImageView.frame = UIScreen.main.bounds
newImageView.backgroundColor = UIColor(white: 0, alpha: 0.8)
newImageView.contentMode = .scaleAspectFit
newImageView.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
let swipe = UISwipeGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
newImageView.addGestureRecognizer(tap)
newImageView.addGestureRecognizer(swipe)
self.view.addSubview(newImageView)
self.navigationController?.isNavigationBarHidden = true
self.tabBarController?.tabBar.isHidden = true
}
@objc func dismissFullscreenImage(_ sender: UITapGestureRecognizer {
self.navigationController?.isNavigationBarHidden = false
self.tabBarController?.tabBar.isHidden = false
sender.view?.removeFromSuperview()
}
如果需要的话,这就是我设置滚动视图内容大小的方式(在添加上面的代码之前可以正常工作):
override func viewDidLayoutSubviews() {
let ogSize = eventMainView.frame.size
eventMainScrollView.contentSize = changeCG(theview: ogSize)
}