Silver Solution: Use a Gesture Dependency


#1

I scanned through several solutions to compare them with mine, but a lot of them felt hacky to me, so I wanted to share my discovery. I’ve noticed that often the bronze and silver challenges will have us really think about and apply the concepts we learned in the chapter. What was this chapter’s main concepts?
[ul][li]Gestures[/li]
[li]Gesture dependencies[/li]
[li]UIGestureRecognizerDelegate[/li][/ul]

The solution I finally came up with was simple. Realizing that both a tap and a pan were firing, I simply set up the pan gesture property to require the tap to fail (gesture dependency) in the initWithFrame:.

The rest of polishing for the solution was to make sure the line was properly deselected if a new line was being drawn, and while I was at it, clearing the UIMenuController from the screen if it was double tapped.

Adding this to the top of touchesBegan:withEvent:

if (self.selectedLine)
{
    [self deselectCurrentlySelectedLine];
}

Helper method:

- (void)deselectCurrentlySelectedLine
{
    self.selectedLine = nil;
    [[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];
}

Adding this to doubleTap: (not part of the challenge, but would still be a bug):

If a line is selected and the menu controller visible, when a new line is just starting the line is deselected, the menu controller gracefully disappears, and the new line continues to be drawn.

Thoughts?