Blocking second (non-consecutive) touch

Discussion in 'iOS Programming' started by 99miles, Mar 19, 2009.

  1. 99miles macrumors member

    Joined:
    Oct 10, 2008
    #1
    I have a situation where you hold your finger and drag to move a view. If you touch another finger and drag while the first one is still down, the view follows that new touch. Is there a simple way to block the second touch down/move when there's already a finger down?
    This is kind of an edge case, but i'd like to fix it.
    Thanks.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I suspect that you'll need to process both touches and determine which is the original and which is the new. Then, just ignore the new one.
     
  3. 99miles thread starter macrumors member

    Joined:
    Oct 10, 2008
    #3
    Yes, but I'm not sure how. How do I differentiate the two?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Perhaps by checking the previous location of each touch? The new touch shouldn't have a location.
     
  5. 99miles thread starter macrumors member

    Joined:
    Oct 10, 2008
    #5
    Unfortunately the second touch does have a location.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    The second touch has a previous location? Hmm, what is it? The same as the first's previous location?
     
  7. 99miles thread starter macrumors member

    Joined:
    Oct 10, 2008
    #7
    No, it's a different location, but since I'm trying to block this second touch in touchesMoved I can't exactly compare it to the previous location.
    I guess if i were only using touchesBegan I could compare to the previous location, but again, it's in touchesMoved.

    thanks
     
  8. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #8
    Supposedly, the UITouch objects remain constant for the duration of each touch-move-untouch sequence, so you could keep track of which touch is which by looking at those.
     
  9. 99miles thread starter macrumors member

    Joined:
    Oct 10, 2008
    #9
    Thanks guys, I finally got it.

    I'm not sure why, but for some reason the touches NSSet passed into the touchesMoved method only had one touch even when there were two. In the end was able to determine if there were multiple touches happening by getting it through the UIEvent:

    NSSet *numTouches = [event allTouches];

    Since I'm not too concerned about this edge case, but just wanted to make the apps' response to it a little prettier just in case, I just bounce out of touchesMoved if i detect multiple touches:

    if( [numTouches count] > 1 )
    return;

    There's undoubtedly a better way, but this works for my purposes.
    Thanks again!
     

Share This Page