Weird issue with Window/View of UITouch object changing to nil

Discussion in 'iOS Programming' started by luckylefty01, Jun 24, 2008.

  1. macrumors member

    Joined:
    Apr 8, 2008
    #1
    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?
     
  2. macrumors newbie

    Joined:
    Jul 30, 2008
    #2
    Hi,
    I am having the exact same issue, did you managed to solve it ?

    Thanks
     

Share This Page