展开的图像视图消失后,滚动视图将不会滚动

时间:2019-07-26 18:11:52

标签: ios swift uiscrollview uiimageview

添加了可点击的代码后,我的图像视图将扩展为全屏。使用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)
    }

0 个答案:

没有答案