0

如何在下面的方法中添加检查,以便该方法仅响应事件“UIControlEventTouchUpInside”?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}

我可以查看活动吗?喜欢

if (event == UIControlEventTouchUpInside)
{
    //Do something
}

上面的代码不起作用。有什么建议我可以用这种方法检查特定事件吗?

4

2 回答 2

1

如果您想使用 touch-up-inside 之类的事件,则无需为低级触摸处理而烦恼。而是addTarget像这样使用:

[button addTarget:self action:@selector(myMethod:) forControlEvents:UIControlEventTouchUpInside];
于 2011-10-14T12:34:35.217 回答
1
Assigned tag value for that view or control, where you want to finding touch. And write this code inside touch method:
UITouch *touch = [touches anyObject];
int tagValue =[touch view].tag;

if(tagValue == <YOUR TAG VALUE>){
//perform your action
} 
于 2011-10-14T10:35:33.200 回答