title: Sketch On UIView Within UIScrollView
body: <p>I am having an issue when trying to sketch on a <code>UIView</code> that is a child view in a <code>UIScrollView</code>. </p>
  
  <p>The problem occurs when you try to sketch on the <code>UIView</code> after it's been zoomed or scrolled on. It seems my sketch code (shown below) does not take into account the zoom or scale of the <code>UIView</code> within the <code>UIScrollView</code> because the lines blur and don't show up where they should. Please let me know if there is something that can be done to my code or provide another solution. </p>
  
  <pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  
        NSLog(@"Draw touchesBegan");
  
        mouseSwipedPSVC = NO;
        UITouch *touch = [touches anyObject];
        lastPointPSVC = [touch locationInView:sheetDrawView];
  
  }
  
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  
        mouseSwipedPSVC = YES;
        UITouch *touch = [touches anyObject];
        CGPoint currentPoint = [touch locationInView:sheetDrawView];
  
        UIGraphicsBeginImageContext(sheetDrawView.frame.size);
        [drawImageView.image drawInRect:CGRectMake(0, 0,       sheetDrawView.frame.size.width, sheetDrawView.frame.size.height)];
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPointPSVC.x, lastPointPSVC.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brushPSVC);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redPSVC, greenPSVC, bluePSVC, 1.0);
        CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
  
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        drawImageView.image = UIGraphicsGetImageFromCurrentImageContext();
        drawImageView.image = UIGraphicsGetImageFromCurrentImageContext();
        [drawImageView setAlpha:opacityPSVC];
        UIGraphicsEndImageContext();
  
        lastPointPSVC = currentPoint;
  
  }
  
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  
       if(!mouseSwipedPSVC) {
          NSLog(@"Check 1");
  
          UIGraphicsBeginImageContext(sheetDrawView.frame.size);
          [drawImageView.image drawInRect:CGRectMake(0, 0, sheetDrawView.frame.size.width, sheetDrawView.frame.size.height)];
          CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
          CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brushPSVC);
          CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redPSVC, greenPSVC, bluePSVC, opacityPSVC);
          CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPointPSVC.x, lastPointPSVC.y);
          CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPointPSVC.x, lastPointPSVC.y);
          CGContextStrokePath(UIGraphicsGetCurrentContext());
          CGContextFlush(UIGraphicsGetCurrentContext());
          drawImageView.image = UIGraphicsGetImageFromCurrentImageContext();
          UIGraphicsEndImageContext();
  
     }
  
  }
  </code></pre>
  
  <p>I should add that this code works fine if the <code>UIView</code> has not been zoomed or scrolled on. Also sheetDrawView is a subview of the <code>UIScrollView</code>.</p>