Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

luckylefty01

macrumors member
Original poster
Apr 8, 2008
32
0
Hey everybody,

This is my code (the point being to add both double (center image on tap) and triple (center image on screen) tap, hence the delay as adapted from page 123 of the iPhone programming guide):

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  
  UITouch *theTouch = [touches anyObject];
  
  CGPoint point = [theTouch locationInView:nil]; //only used for log
  NSLog(@"touches began, point: %f, %f", point.x, point.y);
  // If triple tap
  if ([theTouch tapCount] == 3) {
    [PicMeView cancelPreviousPerformRequestsWithTarget:self];
    [self performProperTapEvent:theTouch];
  }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
 
  // Only single touch for now
  UITouch *theTouch = [touches anyObject];
  
  CGPoint point = [theTouch locationInView:nil]; // only used for log
  NSLog(@"touches ended, point: %f, %f", point.x, point.y);
  
  // If double tap
  if ([theTouch tapCount] == 2) {
    [self performSelector:@selector(performProperTapEvent:) 
               withObject:theTouch 
               afterDelay:(NSTimeInterval)0.5];
  }

}


- (void)performProperTapEvent:(UITouch *)theTouch {

  // If double tap
  if ([theTouch tapCount] == 2) {
    CGPoint currentLocation = (CGPoint)[theTouch locationInView:self];
    [self centerView:picture onPoint:currentLocation];
  }
  
  // If triple tap
  if ([theTouch tapCount] == 3) {
    [self centerView:picture onPoint:self.center];
  }

}


- (void)centerView:(UIView *)view onPoint:(CGPoint)point {
  NSLog(@"Center picture on point: %f, %f", point.x, point.y);
  view.transform = CGAffineTransformMakeTranslation(point.x, point.y);
  [UIView commitAnimations];
}

My problem is that somehow the -locationInView method no longer returns the proper value when it's called in the -performProperTapEvent method. Instead it returns (0,0) no matter the location of the tap.

I believe this is due to that UITouch* that gets passed to -performProperTapEvent no longer having a _view or _window variable associated with it (if I examine theTouch in the debugger they both read proper addresses before theTouch is passed but nil afterwards).

I use similar methods of extracting a point from a touch in other places and they all work fine.

Any thoughts?
 
Hi,
I am having the exact same issue, did you managed to solve it ?

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.