Hittest not accurate after animation

Discussion in 'iOS Programming' started by 99miles, Jan 27, 2009.

  1. 99miles macrumors member

    Joined:
    Oct 10, 2008
    #1
    i have several views that i hittest against.
    sometimes the hittest is very accurate, other times (after it animates to a new location) the hittest is not accurate. The y values are off somewhere and the active touch area is several pixels above where it should be. I'm having a really hard time narrowing down where the problem is. Does anyone have any ideas? I'm not sure if something is going wrong in the convertPoint call, or if the coordinates of the frame being hittested against are just not updated correctly after the animation quit, or ... ?
    Any thoughts would be greatly appreciated. Thanks.
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    Are you updating the element's position after the animation? Animating the layer doesn't change the position of the actual element.
     
  3. 99miles thread starter macrumors member

    Joined:
    Oct 10, 2008
    #3
    It should be fine with this implicit animation:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    mview.frame = newFrame;
    [UIView commitAnimations];

    The view is pretty small, and I'm moving it completely across screen. The hittest is only 10 or so pixels at most off after the animation, so I don't think the problem is as drastic as that, but good thought.


    -Mac
     
  4. 99miles thread starter macrumors member

    Joined:
    Oct 10, 2008
    #4
    I've narrowed it down a little bit. It has nothing to do with the animation. If I remove the animation it still happens.

    I'm creating multiple copies of the same object and placing a few instances on the top of the screen and a few on the bottom. The hittest returns true for the ones on the top when I touch lower on the view than when I do the same on the views in the lower portion of the screen.

    It's so weird. I traced out all the points and point convertions and they all look accurate, but something somewhere is off. It's as if the touch screen coordinates do not exactly match the drawn coordinates over the length of the screen.

    I'm still looking for ANY thoughts. At this point I have this ridiculous hack to add a an increasing numbers of pixels to the point the higher the touch is on the screen:

    pointConvertedForBtn.y += 10 * ((myView.frame.size.height - converted.y) / myView.frame.size.height);
     

Share This Page