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

后端 未结 12 1611
温柔的废话
温柔的废话 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:50

    You can use this method in swift 4.

    add the tag number to the uiview you want to add action

    override func touchesEnded(_ touches: Set, with event: UIEvent?)
    {
        if touches.first?.view?.tag == 10{
            dismiss(animated: true, completion: nil)
            super.touchesEnded(touches , with: event)
        }
    }
    

提交回复
热议问题