jdg / MBProgressHUD

MBProgressHUD + Customizations
http://www.bukovinski.com/
MIT License
16.01k stars 3.56k forks source link

A little extension: tap to hide #308

Closed aral closed 8 years ago

aral commented 9 years ago

Just a little extension for adding tap-to-hide functionality, in case anyone finds it useful. (I am using this for when there is an error so the person has to explicitly dismiss the HUD and the message.) Please feel free to integrate in the library if you feel it would be useful.

class ABProgressHUD:MBProgressHUD
{
    var shouldHideWhenTapped = false

    func hideWhenTapped()
    {
        shouldHideWhenTapped = true
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesBegan(touches, withEvent: event)

        if shouldHideWhenTapped
        {
            hide(true)
        }
    }
}
matej commented 8 years ago

Something like this should now be doable with the build in button. I added a demo example that illustrates that.

Tap to hide is also certainly still possible, but let's keep that as an external extension.