title: Touch coordinates/location distorted
body: <p>Hi all I have a spritekit scene "Menu"
  that I am loading a UIView as a subview (CGScratchViewController.xib)</p>
  
  <pre><code>-(void)addscratchView:(SKView*)view
      {
           CGRect viewFrame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
  
          //ScratchableView : UIView
          myScratchView = [[ScratchView alloc]initWithFrame:viewFrame ];
          self.name = @"menuScene";
          [self.view addSubview:myScratchView];
  
      }
  </code></pre>
  
  <p>ScratchableView class loads a layer that i can erase with my finger an overlay drawing revealing a drawing below</p>
  
  <p>the code seems to be working however the touches are off and seem to be "scaled" somehow, meaning that if I draw in the top left corner the touch is in the correct place, but dragging the finger outward and the touch becomes more and more distorted
   - any thoughts on what to look for to correct this 
   (am a newbie making newbie mistakes)</p>
  
  <p>Scratchableview.h</p>
  
  <pre><code>//  Created by Olivier Yiptong on 11-01-11.
  </code></pre>
  
  <p>//</p>
  
  <pre><code>#import "ScratchableView.h"
  
  
  @implementation ScratchableView
  @synthesize contentScale;
  
  - (id)initWithFrame:(CGRect)frame {
  
      self = [super initWithFrame:frame];
      if (self) {
  
          scratchable = [UIImage imageNamed:@"scratchable.jpg"].CGImage;
          width = CGImageGetWidth(scratchable);
          height = CGImageGetHeight(scratchable);
          self.opaque = NO;
          CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
  
          CFMutableDataRef pixels = CFDataCreateMutable( NULL , width * height );
          alphaPixels = CGBitmapContextCreate( CFDataGetMutableBytePtr( pixels ) , width , height , 8 , width , colorspace , kCGImageAlphaNone );
          provider = CGDataProviderCreateWithCFData(pixels);
  
  
          CGContextSetFillColorWithColor(alphaPixels, [UIColor blackColor].CGColor);
          CGContextFillRect(alphaPixels, frame);
  
          CGContextSetStrokeColorWithColor(alphaPixels, [UIColor whiteColor].CGColor);
          CGContextSetLineWidth(alphaPixels, 20.0);
          CGContextSetLineCap(alphaPixels, kCGLineCapRound);
  
          CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
          scratched = CGImageCreateWithMask(scratchable, mask);
  
          CGImageRelease(mask);
          CGColorSpaceRelease(colorspace);
      }
      return self;
  }
  
  - (void)drawRect:(CGRect)rect {
      CGContextDrawImage(UIGraphicsGetCurrentContext() , [self bounds] , scratched);
  }
  
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  {
  
  
      UITouch *touch = [[event allTouches] anyObject];
      if([[touch view] isKindOfClass:[UIImageView  class]]){
          CGPoint point= [touch locationInView:touch.view];
          NSLog(@"%f%f",point.x,point.y);
  
           location = point;
      }
  
      firstTouch = YES;
  }
  
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  {
      UITouch *touch = [[event touchesForView:self] anyObject];
  
      if (firstTouch) {
          firstTouch = NO;
          previousLocation = [touch previousLocationInView:self];
      } else {
          location = [touch locationInView:self];
          previousLocation = [touch previousLocationInView:self];
      }
  
      // Render the stroke
      [self renderLineFromPoint:previousLocation toPoint:location];
  }
  
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  {
      UITouch *touch = [[event touchesForView:self] anyObject];
      if (firstTouch) {
          firstTouch = NO;
          previousLocation = [touch previousLocationInView:self];
  
          [self renderLineFromPoint:previousLocation toPoint:location];
      }
  }
  
  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
  {
  }
  
  - (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end {
  
      CGContextMoveToPoint(alphaPixels, start.x, start.y);
      CGContextAddLineToPoint(alphaPixels, end.x, end.y);
      CGContextStrokePath(alphaPixels);
      [self setNeedsDisplay];
  }
  
  - (void)dealloc {
      CGContextRelease(alphaPixels);
      CGImageRelease(scratchable);
      CGDataProviderRelease(provider);
  }
  </code></pre>
  
  <p>and Menuscene</p>
  
  <pre><code>-(void)didMoveToView:(SKView *)view {
  
      self.userInteractionEnabled = YES;
  
      SKView * skView = (SKView *)self.view;
      skView.showsFPS = YES;
      skView.showsNodeCount = YES;
  
     // [self createButtons ];
      [self addscratchView:view]; //for testing
  
  
  }
  
  -(void)addscratchView:(SKView*)view
  {
       CGRect viewFrame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
  
      myScratchView = [[ScratchView alloc]initWithFrame:viewFrame ];
      self.name = @"menuScene";
      [self.view addSubview:myScratchView];
  
  }
  </code></pre>
  
  <p>I've tried to convert the coordinates...still not much luck (maybe its not the right thing to do anyways ..</p>
  
  <pre><code>    //convert between view coordinates and scene coordinates
      //coordinate system is not the same in a Sprite Kit scene as they are in a UIView
      UITouch *touch = [[event allTouches] anyObject];
     CGPoint touchlocation = [touch locationInView:touch.view];
      spriteView = (Menu *) spriteView.scene.view;
  
      CGPoint positionInScene = [self convertPoint:touchlocation fromCoordinateSpace:spriteView.scene.view];
  </code></pre>
  
  <p>Video of the effect/distorted touches
  <a href="https://www.youtube.com/watch?v=dMrcufcKpao" rel="nofollow">https://www.youtube.com/watch?v=dMrcufcKpao</a></p>