Graphics Programs Reference
In-Depth Information
In TouchDrawView.m , return YES when the moveRecognizer sends the message to
its delegate.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)other
{
if (gestureRecognizer == moveRecognizer)
return YES;
return NO;
}
Now when the user begins a long press, the UIPanGestureRecognizer will be al-
lowed to keep track of this finger, too. When the finger begins to move, the pan recog-
nizer will transition to the began state. If these two recognizers could not work simultan-
eously, the long press recognizer would start, and the pan recognizer would never trans-
ition to the began state or send its action message to its target.
In addition to the states we've seen previously, a pan gesture recognizer supports the
changed state. When a finger starts to move, the pan recognizer enters the began state and
sends a message to its target. While the finger moves around the screen, the recognizer
transitions to the changed state and sends its action message to its target repeatedly. Fin-
ally, when the finger leaves the screen, the recognizer's state is set to ended, and the final
message is delivered to the target.
Now we need to implement the moveLine: method that the pan recognizer sends its tar-
get. In this implementation, you will send the message translationInView: to the
pan recognizer. This UIPanGestureRecognizer method returns how far the pan has
moved as a CGPoint in the coordinate system of the view passed as the argument.
Therefore, when the pan gesture begins, this property is set to the zero point (where both
x and y equal zero). As the pan moves, this value is updated - if the pan goes very far to
the right, it has a high x value; if the pan returns to where it began, its translation goes
back to the zero point.
In TouchDrawView.m , implement moveLine: . Notice that because we will send the
gesture recognizer a method from the UIPanGestureRecognizer class, the paramet-
er of this method must be a pointer to an instance of UIPanGestureRecognizer
rather than UIGestureRecognizer .
- (void)moveLine:(UIPanGestureRecognizer *)gr
{
// If we haven't selected a line, we don't do anything here
if (![self selectedLine])
Search WWH ::




Custom Search