Four
Four

Reputation: 506

Listen for a UIView's touchesBegan/touchesEnded within an NSObject

So I have an NSObject that accepts a UIView in the init function, and assigns it as a property. The functionality of this behavior class depends on how long the UIView is pressed, using touchesBegan/touchesEnded.

I want to encapsulate this touchesBegan/touchesEnded logic within the NSObject class, in an effort to make this behavior class more modular. Currently, the touchesBegan/touchesEnded functionality is in the UIViewController class, and passed to the behavior.

Is it possible to override and/or "listen" for touchesBegan/Ended in the NSObject class?

Upvotes: 0

Views: 376

Answers (1)

Beirs
Beirs

Reputation: 568

For custom touch handling logic you should subclass UIGestureRecognizer. You can then add it to any view.

Check out the documentation for gesture recognizers and the guide.

Upvotes: 1

Related Questions