Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
so this is how i'm going to try and implement this:

1. throw all my UIButtons into a mutable array.
2. while one button is pressed, remove it from the mutable array.
3. fast enumerate thru the array and cancel all button presses.
4. on touchesEnded add the pressed button back into the mutable array.

in the event that 2 buttons are pressed at once, this would be to insure that only one button can be pressed at a time, so that multiple actions don't execute (and cause animation/visual errors).

but i'd like to know if there is a better way to do this?
 
i think i tried that, but found that it was still possible to touch 2 buttons at once, and that a cancel button pressed method was required. or maybe i just coded it wrong / imagined things?
 
Code:
[UIView exclusiveTouch]

ohhh... nice...

not totally clear after reading the docs on exclusiveTouch, though... i'll have a lot of work removing bools and other variables to impliment exclusiveTouch, so before i start – i have a full screen that accepts touch events, evaluates CGPoint distances and moves a UIImageView accordingly. above the UIImageView i have UIButtons. can i simply insert the following code to make this work?:

Code:
//loadView
[self.view setExclusiveTouch:YES];
[self.button1 setExclusiveTouch:YES];
[self.button2 setExclusiveTouch:YES];
[self.button3 setExclusiveTouch:YES];

so if the buttons are not being touched, the main view is (since it's the entire screen). but if button1 is touched, it will cancel all previous touches (touchesCancel connection in IB?) and disallow touching of the main view or the other buttons until touchesEnded?
 
I haven't used the exclusiveTouch property so I'm not certain. The way I read the docs if you set it on your buttons then once a button is touched no other button can send a touch. I don't think it's essential that you set this property for all views in a screen. I guess I'm not sure what happens if you first touch a view that's not exclusive and then touch one that is.

It should be simple enough to figure it out though.
 
my code above works. however, it seems that if you only have 2 buttons (or views) i think that only one needs to be set with the exclusiveTouch property in order for both to benefit.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.