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

alexandergre

macrumors member
Original poster
Jul 28, 2009
58
0
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.


Code:
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.