touchesBegin & touchesMove Xcode Obj C Question
Posted
by AndrewDK
on Stack Overflow
See other posts from Stack Overflow
or by AndrewDK
Published on 2010-06-16T01:37:17Z
Indexed on
2010/06/16
1:42 UTC
Read the original article
Hit count: 467
So I have my app working good when you press and drag along. I also have UIButtons set to Touch Down in Interface Builder.
As well when you drag you need to drag from the outside of the UIButton. You cannot click on the UIButton and drag to the other.
TOUCHES MOVED:
Code:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(oneButton.frame, location))
{
if (!oneButton.isHighlighted){
[self oneFunction];
[oneButton setHighlighted:YES];
}
}else {
[oneButton setHighlighted:NO];
}
//
if(CGRectContainsPoint(twoButton.frame, location))
{
if (!twoButton.isHighlighted){
[self twoFunction];
[twoButton setHighlighted:YES];
}
}else {
[twoButton setHighlighted:NO];
}
}
TOUCHES BEGAN:
Code:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(oneButton.frame, location))
{
[self oneFunction];
[oneButton setHighlighted:YES];
}
if(CGRectContainsPoint(twoButton.frame, location))
{
[self twoFunction];
[twoButton setHighlighted:YES];
}
}
I want to be able to click on any of the button fire the function & also be able to drag from one button on to the other and fire that function.
So basically just being able to click on a button and slide your finger over and activate the other button without having to press and slide from outside of the button.
I think I'm close, need a bit of help. Hope thats clear enough.
Thanks.
© Stack Overflow or respective owner