How to use the gesture recognizer for iOS

In the workshop page, I've added a class and example to get swipe recognition in iOS using the native GestureRecognizers. It takes ofxGestureRecognizer as a starting point

Here are the instructions

1. put the ofxiOSSwipeRecognizer folder in your addons folder and either
- create an Xcode project with the projectGenerator with the addon checked.
- drag it to the addons folder of an existing project.

2. In testApp.h, create an instance of the swipe recogniser (you should create one instance per direction you want to detect).

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }ofxiOSSwipeRecognizer leftSwipeRecognizer; {/syntaxhighlighter}

3. add a method to that will receive the swipe

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }void onSwipeLeft(ofxiOSSwipeEventArgs & args); {/syntaxhighlighter}

4. in testApp.cpp call swipeRecognizer.setup on setup passing the direction of the swipe (if you don't pass any it'll use left, which is apple's default)

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }leftSwipeRecognizer.setup(OFXIOS_SWIPE_DIRECTION_RIGHT);{/syntaxhighlighter}

5. add a listener for the swipeRecognized event


ofAddListener(leftSwipeRecognizer.swipeRecognized, this, &testApp::onSwipeLeft);

6. implement the onSwipeLeft method and do cool things with it

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }void testApp::onSwipeLeft(ofxiOSSwipeEventArgs & args){ .... }{/syntaxhighlighter}


Difficulty: ●○○○○


Last updated: 9 years ago