-3

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...

Dan Lewis
  • 21
  • 4
  • I think Dan Lewis want to ask how to set "hiden" value for a UIButton on Xcode, not within Objective-C. So, this question shouldn't close. It's useful. – Nguyen Minh Binh Jan 14 '13 at 09:34

4 Answers4

2

have you tried button.hidden = YES;?

justin
  • 104,054
  • 14
  • 179
  • 226
  • hi Justin, how would i implement this? – Dan Lewis Jan 10 '12 at 23:49
  • @Dan basically, you would combine Mats answer with mine to do what you have outlined in your OP. `buttons` in my example would be one of the two buttons you want to hide, and it would go in the body of Mats `doubleTap` method. if my answer makes no sense or *if* you don't know what `button` is supposed to represent or how you would access it, then you should start with smaller programming exercises - perhaps an introductory book on iOS development. – justin Jan 11 '12 at 00:09
  • Hi Justin, i think whats confused me is that his method starts void (where would i put this ?) i'm a beginner i know but you guys are far easier to understand than some of the literature in the programming guide, the crazy thing is i'm capable of implementing far more advanced code, sometimes the easiest are the hardest... please – Dan Lewis Jan 11 '12 at 00:25
  • @Dan the method definition goes in the `@implementation` block. this is very basic objc - a book which teaches you the language would help you. you can't write an objc program without knowing this stuff. good luck. – justin Jan 11 '12 at 00:43
  • hi mate... i understand that.. think i've come across incorrectly (still, will get the books haha) but all i'm misunderstanding is the code written for the button methods.. understand the implementation.. could you write for me the code needed for the method? and i'll buy the books promise – Dan Lewis Jan 11 '12 at 00:46
  • @Dan we understand you don't understand what you are talking about. you need to study, practice, and write if you want to program. take some time away from your projects to learn. it will take time and patience to learn to program comfortably (e.g. 1-2 years). if you don't have that, consider hiring somebody. – justin Jan 11 '12 at 02:21
  • @Dan and that's not to say we don't want to help; we just won't spoonfeed you to your app's release. – justin Jan 11 '12 at 02:27
0

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.

  • Hi Greg... thanks for the reply, i've dragged the gesture into the View controller but when you say link it to a selector what do you mean? I have two buttons on the screen that i want to hide when i double tap so...i've learnt an awful lot in the 3 months i've been doing this and have never been on the forum before, i can handle far more complicated things...promise – Dan Lewis Jan 10 '12 at 22:36
  • Hi Dan, if you right click on the Tap Gesture Recognizer in Interface Builder then a view will popup with 'selector' and a hollow circle next to it. Click in the hollow circle and drag the line to "File's Owner" (probably). That should trigger a list of method options. If you've correctly setup the show/hide method in the .h (it may need to be an - (IBAction) then it should show and you can select it. That method should now be called each time the gesture is detected. – GregularExpressions Jan 10 '12 at 22:49
  • Hi Greg...Don't hate me, what would be the exact method i place into the .h file? in a year's time when i'm making millions i'll come and find you.... – Dan Lewis Jan 10 '12 at 23:09
  • - (IBAction) gestureDetected: (id) sender; – GregularExpressions Jan 11 '12 at 09:14
  • You then of course need the same method in your .m similar to my original example above. – GregularExpressions Jan 11 '12 at 09:14
0

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.

Mats Stijlaart
  • 5,058
  • 7
  • 42
  • 58
  • hi mats thanks for answering, what would need to write as far as the method is concerned? i have two buttons that i want to disappear (i know this is a very simple question and so i appologise) – Dan Lewis Jan 10 '12 at 23:46
0

Learn how to use NSTimmer or the sleep() function to create the delay between the double tap.