PDA

View Full Version : TochesMoved question




alexandergre
Dec 1, 2009, 09:56 AM
What I am trying to do is that if you want to move myButton, your finger has to be on myButton.
Right now if you drag anywhere on the screen, myButton is also moved. How can I fix it?

thanks for you help.


BOOL FingerOnButton;
@implementation Stockholm


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:myControlView];
[self dispatchFirstTouchAtPoint:touchPoint forEvent:nil];

}




-(void)dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event
{
if (CGRectContainsPoint([myButton frame], touchPoint))
FingerOnButton =TRUE;

else
FingerOnButton =FALSE;
}





-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:myControlView];
for (UITouch *touch in touches) {
[self dispatchTouchEvent:[touch view] toPosition:touchPoint];
}
}




-(void)dispatchTouchEvent:(UIView *)theView toPosition:(CGPoint)position
{

if(FingerOnButton =TRUE){

myButton.center=CGPointMake(position.x, 20);
}
}


bump
basicly my question is:
how to activate touch only on a specific area?