IOS - How to hide a view by touching anywhere outside of it

后端 未结 12 1577
温柔的废话
温柔的废话 2020-12-29 23:23

I\'m new to IOS programming, I\'m displaying a view when a button is clicked, using the following code inside the button method.

 @IBAction func moreButton(_         


        
12条回答
  •  独厮守ぢ
    2020-12-29 23:42

    Inside the moreButton selected, you can do something like this

     @IBAction func moreButton(_ sender: Any)
        {
            self.helpView.isHidden = false
            let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissView))
            view.addGestureRecognizer(tap)
        }
    
        func dismissView() {
            self.helpView.isHidden = true
            self.view.removeGestureRecognizer(tap)
        }
    

提交回复
热议问题