Views and Gestures - Gestures

4 important questions on Views and Gestures - Gestures

What 2 things must you do to use a gesture recognizer

1. Create and add a gesture recognizer to a UIView.
2. Providing the implementation of a method to "handle" that gesture when it happens

"Who" does the handling when a gesture is recognized?

Most of the time the view does, but it can also be done by the controller.

How do you add a gesture recognizer to a view?

first create one:
UIPanGestureRecognizer *pangr = [[UIPanGestureRecognizer alloc]initWithTarget:nameOfTheObjectThatHandlesTheGesture action:@selector(nameOfHandlerMethod:)];

then add it to the view:
[nameOfTheTargetView addGestureRecognizer:pangr];
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

How can you get the recognizers state?

A gesture recognizer has a @property "state" which you can check, i.e.:
if (recognizer.state == UIGestureRecognizerStateChanged) ...

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo