简体   繁体   English

在iOS中连接触摸事件

[英]Connect touch event in ios

Now that I know that NSEvent does not exist on ios - what do I need to do to capture an event like touchUpInside and cause it to call my method to handle it, WITHOUT Interface Builder? 现在,我知道NSEvent在ios上不存在-我需要怎么做才能捕获诸如touchUpInside之类的事件,并使它调用我的方法来处理它,而无需使用Interface Builder?

I think this like asking how do I link an event to an outlet without IB... 我认为这就像问我如何将事件链接到没有IB的插座...

I know it can be done, but I can't find anything that shows how - except Mac-only examples that use NSEvent. 我知道可以做到这一点,但是我找不到任何能显示出这种效果的东西-除了使用NSEvent的仅限Mac的示例。

Take a look at this method in UIControl: 看看UIControl中的此方法:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

Each of the different event types has a constant, such as UIControlEventTouchUpInside. 每个不同的事件类型都有一个常量,例如UIControlEventTouchUpInside。 Here's an example of it being used: 这是一个使用示例:

[addButton addTarget:self action:@selector(increment:) forControlEvents:UIControlEventTouchDown];

Look here for the values of controlEvents, listed in the Constants section. 在此处查看“常量”部分中列出的controlEvents的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM