Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-21-2009, 01:17 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 4
Unhappy How to detect multiple button presses at the same time

I searched around for a while on the Internet and this forum but I could not find my answer.

I am creating an application that has a screen filled with two big buttons. As part of the functionality, I want to be able to detect if the user has multi-touched by pressing both buttons at the same time. I cannot seem to get that to work.

Thanks.
bhmayo is offline   Reply With Quote
Old 08-21-2009, 02:52 AM   #2 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
Default

What kind of action do you want to happen when the user has pressed any combination of the two buttons (button1, button2, or both)?
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Old 08-21-2009, 08:56 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 4
Default

Quote:
Originally Posted by drewag View Post
What kind of action do you want to happen when the user has pressed any combination of the two buttons (button1, button2, or both)?
It gets a bit odd what I want to do upon detection that both buttons are pressed. For my application, the standard view is a TabBar view but when a particular TabItem is selected, the TabBar view does away and the two-button view takes full screen. I want to make it where when both buttons are pressed the application navigates the user back to the TabBar view.

I can work through the specific of that navigation/view manipulation, I just need to understand how, during the pressing of the buttons, I can at least have a method (action) invoked.

thanks.
bhmayo is offline   Reply With Quote
Old 08-21-2009, 12:27 PM   #4 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
Default

Quote:
Originally Posted by bhmayo View Post
It gets a bit odd what I want to do upon detection that both buttons are pressed. For my application, the standard view is a TabBar view but when a particular TabItem is selected, the TabBar view does away and the two-button view takes full screen. I want to make it where when both buttons are pressed the application navigates the user back to the TabBar view.

I can work through the specific of that navigation/view manipulation, I just need to understand how, during the pressing of the buttons, I can at least have a method (action) invoked.

thanks.
But my questions is if anything will happen when pressing one button? If nothing will happen with just one button it is easier to wait for both being pressed. It would however still be possible to do it, you will just probably want to use a timer to wait to see if a second finger comes down. So does pressing one button do anything?
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Old 08-21-2009, 03:48 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 4
Default

Quote:
Originally Posted by drewag View Post
But my questions is if anything will happen when pressing one button? If nothing will happen with just one button it is easier to wait for both being pressed. It would however still be possible to do it, you will just probably want to use a timer to wait to see if a second finger comes down. So does pressing one button do anything?
sorry about that, I misunderstood.

Yes, if an individual button is pressed, a particular action happens. I attempted, in each individual button action, to inquire the state of the other button, but that does not seem to work. I am still a bit new at iPhone development (but love it!) so I must be checking state incorrectly.

Thanks.
bhmayo is offline   Reply With Quote
Old 08-21-2009, 03:59 PM   #6 (permalink)
www.ihustleapps.com
 
Join Date: Jul 2009
Location: Long Island
Posts: 102
Default

Quote:
Originally Posted by bhmayo View Post
sorry about that, I misunderstood.

Yes, if an individual button is pressed, a particular action happens. I attempted, in each individual button action, to inquire the state of the other button, but that does not seem to work. I am still a bit new at iPhone development (but love it!) so I must be checking state incorrectly.

Thanks.
mayb like this:

in .h
Code:
int *buttonpressed;

- (IBAction)twotouch;
- (IBAction)lefttouch;
- (IBAction)righttouch;
then in .m
Code:
- (void)viewDidLoad {
buttonpressed = 0;
}

- (IBAction)twotouch {
buttonpressed = buttonpressed + 1;
if (buttonpressed == 2) {
//do code for two buttons pressed here
}
}

- (IBAction)lefttouch {
buttonpressed = 0;
//do something here for 1st button pressed solo
}

- (IBAction)righttouch {
buttonpressed = 0;
//do something here for 2nd button pressed solo
}
I would then link two touch to TOUCH DOWN INSIDE for both buttons
then i would link left touch to TOUCH UP INSIDE for the 1st button
then i would link right touch to TOUCH UP INSIDE for the 2nd button

hmm..

Last edited by wtngclan; 08-21-2009 at 04:03 PM.
wtngclan is offline   Reply With Quote
Old 08-21-2009, 04:16 PM   #7 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
Default

Quote:
Originally Posted by bhmayo View Post
sorry about that, I misunderstood.

Yes, if an individual button is pressed, a particular action happens. I attempted, in each individual button action, to inquire the state of the other button, but that does not seem to work. I am still a bit new at iPhone development (but love it!) so I must be checking state incorrectly.

Thanks.
So this is probably what I would do. Setup a bool for if a button is When a single button is pressed I would start a timer to activate the single button timer (kButtonTapDelay would be some constant that you define in your h file ex: #define kButtonTapDelay .2
Code:
-(IBAction)button1Clicked
{
   if(_button1Clicked)
      return;
   if(_button2Clicked)
   {
      [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(button2SingleClick) object:nil];
      // Do some action for both buttons
      [self twoButtonClick];
   } else
   {
      [self performSelector:@selector(button1SingleClick) withObject:nil afterDelay:kButtonTapDelay];
      _button1Clicked = YES;
   }
}
-(IBAction)button2Clicked
{
   if(_button2Clicked)
       return;
   if(_button1Clicked)
   {
      [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(button1SingleClick) object:nil];
      // Do some action for both buttons
      [self twoButtonClick];
   } else
   {
      [self performSelector:@selector(button1SingleClick) withObject:nil afterDelay:kButtonTapDelay];
      _button2Clicked = YES;
   }
}
-(void)button1SingleClick
{
   _button1Clicked = NO;
   // Do some action for just button 1
}
-(void)button2SingleClick
{
   _button2Clicked = NO;
   // Do some action for just button 1
}
So here is the basic concept of this. Each button calls their own buttonXClicked. This makes it so that a bool (stored in your class) _buttonXClicked is YES and then it says run the single action after a small delay. The small delay is to wait to see if the other button was pressed as well. Then if the other button is pressed it checks to see if the first button was pressed already. If it was, then it cancels the single button click and does the twoButtonAction. If you don't understand that I can try to clarify more.
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Old 08-21-2009, 04:22 PM   #8 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
Default

Quote:
Originally Posted by wtngclan View Post
I would then link two touch to TOUCH DOWN INSIDE for both buttons
then i would link left touch to TOUCH UP INSIDE for the 1st button
then i would link right touch to TOUCH UP INSIDE for the 2nd button

hmm..
With this method both single button actions are going to be fired when lifting up.
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Old 08-21-2009, 05:21 PM   #9 (permalink)
www.ihustleapps.com
 
Join Date: Jul 2009
Location: Long Island
Posts: 102
Default

Quote:
Originally Posted by drewag View Post
With this method both single button actions are going to be fired when lifting up.
Code:
- (void)viewDidLoad {
buttonpressed = 0;
}

- (IBAction)twotouch {
buttonpressed = buttonpressed + 1;
if (buttonpressed == 2) {
//do code for two buttons pressed here
}
}

- (IBAction)lefttouch {
if (buttonpressed != 2){
buttonpressed = 0;
//do something here for 1st button pressed solo
}
}

- (IBAction)righttouch {
if (buttonpressed != 2) {
buttonpressed = 0;
//do something here for 2nd button pressed solo
}
}
wtngclan is offline   Reply With Quote
Reply

Bookmarks

Tags
button, multitouch, multitouch event, uibutton

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 270
20 members and 250 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, iDifferent, JasonR, macquitzon216, mer10, prchn4christ, Rudy, sacha1996, sneaky, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:11 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0