ios - Is it possible to create a tap based on the location of the taps? -


i'm trying create program in when tap in same location last touch ended, circle changes color. i've tried using previouslocationinview method using logic along lines of: "if touchesbegan location == previoustoucheslocation, change color blue." method didn't work because touchesbegan , previoustouchlocation coordinates have same value changed color whenever tapped screen regardless of location. same result if substitute previoustouchlocation touchesended. here code if thinks help.

-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     uitouch* touch = [touches anyobject];     touchlocation = [touch locationinview:self.view];     lasttouchlocation = [[touches anyobject] previouslocationinview:self.view];     distance_x = touchlocation.x - cvx;     distance_y = cvy - touchlocation.y;     previousdistance_x = lasttouchlocation.x - cvx;     previousdistance_y = cvy - lasttouchlocation.y;      if ((previousdistance_x == distance_x) && (previousdistance_y == distance_y)) {         if (([cv.color isequal:[uicolor redcolor]])) {            [cv setcolor:[uicolor bluecolor]];         }         else             [cv setcolor:[uicolor redcolor]];     } } 

-previouslocationinview: gives previous location of touch that's moving on screen. doesn't give location of different, ended, touch.

what you're going have is, on first touch, store touch's location in property or ivar. then, on second touch, compare location stored location. you'll need allow leeway—fingers not pixel-accurate in way mice can be—so touch that's moved ten or twenty pixels should count double-tap.

actually, come think of it, best bet might use uitapgesturerecognizer numberoftapsrequired set 2. handle detection logic you, , can combine other gesture recognizers build more complex behaviors.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -