2011-10-14 36 views
0

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

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

我可以检查事件吗?像

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

上述代码不起作用。任何建议如何检查此方法中的特定事件?

回答

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 
} 
1

如果你要使用像触摸式,里面的事件,你不应该需要低级别的触摸操作打扰。相反使用addTarget像这样:

[button addTarget:self action:@selector(myMethod:) forControlEvents:UIControlEventTouchUpInside]; 
相关问题