difference between locationOfTouch:inView and locationInView

Discussion in 'iOS Programming' started by daproject85, Jul 9, 2012.

  1. daproject85 macrumors member

    Apr 13, 2011
    Hi Forum,

    i want to see if anyone can please explain the difference between these two methods for me. I have read the apple docs over and over again but i do not understand the difference. So here is my code... in my view controller i have

     UITapGestureRecognizer *tripleTapToAdjustOrigin = [[UITapGestureRecognizer alloc]
        tripleTapToAdjustOrigin.numberOfTapsRequired = 3;
        [self.graphview addGestureRecognizer:tripleTapToAdjustOrigin];
    and in my view class i have the method "tripleTapToAdjustOrigin" and in it i have

    - (void)tripleTapToAdjustOrigin:(UITapGestureRecognizer *)gesture
        if((gesture.state == UIGestureRecognizerStateEnded))
               self.axisOrigin = [gesture locationInView:self];
    when i use locationInView it works perfectly, if i use locationOfTouch:0 inView:self also works, but picking any number other than 0 , like 1 or 2 crashes my program. My (incomplete) understanding is that the index determines which touch we are interested it....so how does it really work? i will really appreciate the help.
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Since you're detecting a triple-tap, all touches will have occurred at the same location (basically). Therefore, there will only be one touchIndex (at index 0) for you to query. If you had been trying to detect multi-touches (i.e. more than one touch in multiple locations), then you would be able to access touches beyond the 0 index.

Share This Page