Peeter Vedic Peeter Vedic - 5 months ago 57
Swift Question

Swift press button function, press again for reverse

I've got a simple IBAction that performs a method (let's just say shows subview). When I press this button again I want to perform another method (hides subview).

I have done the coding for the show/hide. I have tried using a Boolean but am unsure of the syntax. I also tried using an if/else statement like this:

var doubleTap = false

if (doubleTap) {
//hide view
} else {
//show view
}


If someone could shed some light on this that'd be great!

Answer

change to code like below in the Button Press Method:

var doubleTap : Bool! = false
if (doubleTap) { 
    //Second Tap 
    doubleTap = false
} else {
    //First Tap 
    doubleTap = true
}
Comments