我有一个自定义视图,它是UIView的子类。它有一个touchesEnded事件,但是它不会出现在接口生成器中(在Events下)。我想知道如何将该方法放入我的视图控制器中,这样每当touchesEnded触发时,方法就会触发。然而,我正在考虑使用目标操作,
下面的代码不起作用,因为forControlEvents:UIControlEventTouchesEnded不存在。所以我不知道如何从我的子类UIView的类中获取touchesEnded方法。
[customView addTarget:self action:@selector(actionWithUIControlEvent:) forControlEvents:UIControlEventTouchUpInside];任何帮助都将不胜感激!
发布于 2011-07-18 06:06:16
让你的视图控制器来处理事件消息。在其中实现touchesEnded:withEvent:方法,然后调用第二个方法。
发布于 2011-07-18 06:03:58
在视图控制器中,您应该能够在自定义视图上创建UITapGestureRecognizer。您可以检查识别器的状态,以查看是否在touches ended:UIGestureRecognizerStateEnded上收到消息。
https://stackoverflow.com/questions/6727043
复制相似问题