Question:
I’m trying to change the background color of a view using UITapGestureRecognizer. Essentially when the user taps, I want the background to change colors, and on release or complete, the background color go back to nil, or no background color.
This action is similar to a default UIButton, but I need this to be on a view instead.
Problem:
I’ve tried using code similar to:
- (void)handleTapGesture:(UITapGestureRecognizer *)recognizer
{
if(recognizer.state == UIGestureRecognizerStateBegan) {
self.backgroundColor = [UIColor greenColor];
}
if(recognizer.state == UIGestureRecognizerStateEnded) {
self.backgroundColor = nil;
}
}
without any sucess. Is this the correct way to know when a tap gesture starts and ends?
It might be easier to use these methods which should already be part of the responder chain in your UIViewController, unless they are being handled elsewhere already