Lets say I wan\'t to add 1 to an integer. This will only be done when I push down on a UIButton and then release my finger on another UIButton.
//Initalize a BOOL variable to know if you started the touch in the right place.
BOOL correctStart = NO;
//Get the location of the first touch, if its in the first button make correctStart = YES.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches) {
if ([touch locationInView:button1.view]) {
correctStart = YES;
}
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches) {
if (([touch locationInView:button2.view]) && (correctStart == YES)) {
anInteger++;
}
}
correctStart = NO;
}
I did not try this code as I am not at my mac, so your results may vary, but this should get you going in the right direction.