Solving silver challenge in a different way


#1

I solved the Silver challenge in a bit different way as mentioned here.
Anyway, I am attaching solution. The changes I had to add to the code
are highlighted with comments:

[code]

  • (void)longPress:(UIGestureRecognizer *)gr
    {
    if ([gr state] == UIGestureRecognizerStateBegan)
    {
    CGPoint point = [gr locationInView:self];
    [self setSelectedLine:[self lineAtPoint:point]];

      longPressSelection = YES; // This is the change I had to add. 
                                            // longPressSelection is an ivar of type BOOL, set to NO in the init method
     
      if ([self selectedLine])
      {
          [linesInProcess removeAllObjects]; 
      }
    

    }
    else
    if ([gr state] == UIGestureRecognizerStateEnded)
    {
    longPressSelection = NO; // This change I added

      [self setSelectedLine:nil];
    

    }

    [self setNeedsDisplay];
    }[/code]

[code]

  • (void)moveLine:(UIPanGestureRecognizer *)gr
    {

    if (![self selectedLine])
    return;

    if ([gr state] == UIGestureRecognizerStateChanged && longPressSelection == YES ) // This change I added inside if
    {
    CGPoint translation = [gr translationInView:self];

      [/code]