I am new to iOS/objective-C and I wanted to know how to build custom gestures. In particular, if a user taps the top right of the screen and slides his/her finger down the edge
You can do it by seeing either positive or negative delta in the x and y axis of the touch. for instance, a check mark gesture (√) will be a negative delta followed by a positive delta in the y while there is always a negative delta with the x and the touch ends at a lower height than where it started. Add more fingers you add more checks.
Pseudocode:
bool firstStroke, secondStroke, motion, override;
while (touchdown){
if (yDelta < 0){firstStroke = TRUE;}
if (firstStroke && yDelta > 0){secondStroke = TRUE;}
if (xDelta < 0){motion = TRUE;}
if (xDelta > 0 || (firstStroke && secondStroke && yDelta < 0)){override = TRUE;}
}
if (firstStroke && secondStroke && motion && start.y > end.y && !override){
return TRUE;
}else{
return FALSE;
}
The while command means that while the touch is down, check for 3 things:
-If the touch has moved down
-If after the touch has moved down that it has moved up again
-If the touch is moving a right to left
The forth check is to see if the touch ever moved left to right or if after the gesture moved down after the gesture has been finished.
After the touch is finished, there is one more check to see if the gesture moved correctly, if the points started and ended in the correct places and if the gesture moved in an incorrect motion (override).
Hope that helps.