我有一个各种UIButtons网格(5 x 5)...现在我有一个UIControlEventTouchUpInside ..这意味着当用户想要选择各种按钮时需要逐个按下...
当用户将手指拖过各种按钮时,如何激活按钮。
以下是我使用的代码:
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];
}
答案 0 :(得分:0)
你也可以对:
做出反应UIControlEventTouchDragEnter或 UIControlEventTouchDragExit
处理这些案件。
答案 1 :(得分:0)
好吧最后我解决了这个问题:
-(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];
}
}
}
我覆盖/评论按钮设置操作,因为不适用于我:
//[lletra addTarget:self action:@selector(lletraPitjada:) forControlEvents: UIControlEventTouchDragEnter];
和无效的用户互动,因为UITouch不喜欢按钮:
lletra.userInteractionEnabled = NO;
瞧......一切都很完美......