Graphics Programs Reference
In-Depth Information
the target to determine why it has been sent the action message and take the appropriate
action.
Here's the plan for implementing our action method longPress: . When the view re-
ceives longPress: and the long press has just begun, we will select the closest line to
where the gesture occurred. This allows the user to select a line while keeping the finger
on the screen (which is important in the next section when we implement panning). When
the view receives longPress: and the long press has ended, we will deselect the line.
In TouchDrawView.m , implement longPress: .
- (void)longPress:(UIGestureRecognizer *)gr
{
if ([gr state] == UIGestureRecognizerStateBegan) {
CGPoint point = [gr locationInView:self];
[self setSelectedLine:[self lineAtPoint:point]];
if ([self selectedLine]) {
[linesInProcess removeAllObjects];
}
} else if ([gr state] == UIGestureRecognizerStateEnded) {
[self setSelectedLine:nil];
}
[self setNeedsDisplay];
}
Build and run the application. Draw a line and then hold down on it; the line will turn
green and be selected and will stay that way until you let go.
Search WWH ::




Custom Search