How can I programmatically link an UIView or UIImageView with an event like “touch up inside”?

一笑奈何 提交于 2019-12-01 08:15:50

In SDK version 3.2 (could be earlier i donno), you can add gesture recognizers to a UIView. UIGestureRecogniser is an abstract class that allows you to define a gesture (tap, pinch, swipe, etc) and add it to a UIView and when the gesture recognizer, recognizes the gesture, it fires up an action on a target of your desire.

read all about it in the docs... :D

It is not possible to use Target-Action Model here because UIImageView is not inherited from UIControl like UIButton it is derived from UIView. So if u want to track the touches on views or image views first u have to custom class and then place the touch began event in to it and perform the operation. Otherwise use UIGestures that may help u lot

UIViews don't generally need IBAction outlets to receive touch events. Typically, if a view is under the control of a viewController, you can check for UITouch Events using touchesBegan methods. To set the target and selector for control actions you can also use:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!