I have a grid of various UIButtons (5 x 5)... Now I have a UIControlEventTouchUpInside.. this means that when the user wants to choose various buttons need to press each, one by one...
How can I do to activate the buttons when the user is dragging his finger over various buttons.
Here is the code I use:
for (i = 0; i < num_caselles; i++)
{
lletra = [[UIButton alloc] initWithFrame:CGRectMake(POS_H, POS_V, mida_boto, mida_boto)];
[botones addObject: lletra];
[lletra setTitle: [caselles objectAtIndex: i] forState: UIControlStateNormal];
lletra.tag = i;
[lletra addTarget:self action:@selector(lletraPitjada:) forControlEvents: UIControlEventTouchUpInside];
}
Ok finally I resolved this way :
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(UIButton*boton in botones)
{
if(CGRectContainsPoint([boton frame], location) && boton.tag != boton_anterior)
{
boton_anterior = boton.tag;
[self lletraPitjada:boton];
}
}
}
I override/commented the button set action, because is not working for me :
//[lletra addTarget:self action:@selector(lletraPitjada:) forControlEvents: UIControlEventTouchDragEnter];
and deactive user interaction, because UITouch dont like buttons :
lletra.userInteractionEnabled = NO;
And voilà... all is working perfect...