I’m going to be using the same code that I have in my view controller in several views and I don’t want to have to paste the code into each.
Can someone show me a few lines of code showing me how to do this ?
I’m guessing i’m going to have to declare an instance of the class in the interface and put a hand back method for each of touch functions I’ll be sub classing ?
If I understand the question correctly you want the same bit of code executed for touchesBegan, touchesMoved… from each of your views.
The way I would do this would be using the delegate pattern.
This will let you put all your touch handling code in one place (in a class that conforms to the ViewTouchDelegate protocol), and give that delegate to each of your views.
In my example I have made the signature of touchesBegan the same as UIResponder’s touchesBegan, but you can tailor it to your needs.
Edit: Example ViewTouchDelegate
Define any additional methods you need in the ViewTouchDelegate protocol for your purposes, for example touchesMoved, touchesEnded, yourOwnCustomEvent.