I want to create a gesture so that when the user double taps the screen all the buttons disappear until it is then double tapped again....
Have searched hi and low for the answer but I guess I need to try harder...PLEASE HELP haha
would greatly appreciate it if you could specify what goes in the .h and the .m respectfully...
sorry for the dumb question once again...
have you tried button.hidden = YES;
?
If you intend to have the buttons animate in and out then you may find [button setAlpha:0]
and
[button setAlpha:1]
more useful, excuse the crude example:
- methodTheDoubleTapGuestureCalls
{
if (button.alpha == 0)
[UIView animateWithDuration:0.5 animations:^{
[button.alpha setAlpha:1];
}
}
}
If you're struggling with the gesture then in iOS 5 you can drag a gesture recogniser onto a view in Interface Builder, set the gesture you're interested in then link it to a selector.
Learn how to use NSTimmer or the sleep() function to create the delay between the double tap.
Try the UIGestureRecognizer
class.
This implementation will allow you to recognize different predefined user interactions.
UITapGestureRecognizer
is the subclass that you need.
In your controller you can do the following:
// Do this in your viewDidLoad
// Instance variable
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap)];
[recognizer setMinimumNumberOfTouches:2];
[recognizer setMaximumNumberOfTouches:2];
And add a method for the buttons:
- (void) doubleTap {
//Hide/unhide buttons
}
For the buttons should first add them as outlets (instance variables with the keyword IBOutlet) and you should add them to your view.
Make sure to link them up. See here.
When you link them up, you could use the following statement to hide/unhide them.
First option:
buttonOne.hidden = !buttonOne.hidden
buttonTwo.hidden = !buttonTwo.hidden
Second option:
//Add a instance variable hideButtons of type BOOL. I prefer this, your always sure the hidden value for each button has the same value.
hideButtons = !hideButtons
buttonOne.hidden = hideButtons
buttonTwo.hidden = hideButtons
In your viewDidLoad you should explicitly set hideButtons to your initial value. Although it is not required when the boolean value is false, but i always do it for clarity.
Hope this was helpful.