difference between locationOfTouch:inView and locationInView

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

  1. daproject85 macrumors member

    Joined:
    Apr 13, 2011
    #1
    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

    Code:
     UITapGestureRecognizer *tripleTapToAdjustOrigin = [[UITapGestureRecognizer alloc]
                                                            initWithTarget:self.graphview 
                                                            action:@selector(tripleTapToAdjustOrigin:)];
        tripleTapToAdjustOrigin.numberOfTapsRequired = 3;
        [self.graphview addGestureRecognizer:tripleTapToAdjustOrigin];
    
    and in my view class i have the method "tripleTapToAdjustOrigin" and in it i have

    Code:
    - (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

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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