how detect swipe gesture direction?

Here is an example from one of my projects: // … UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:swipeLeft]; UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; swipeRight.direction = UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:swipeRight]; UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; swipeUp.direction = UISwipeGestureRecognizerDirectionUp; [self.view addGestureRecognizer:swipeUp]; UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; swipeDown.direction … Read more

Gesture problem: UISwipeGestureRecognizer + UISlider

The simplest way to handle this is probably to prevent the gesture recognizer from seeing touches on your slider. You can do that by setting yourself as the delegate, and then implementing – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isKindOfClass:[UISlider class]]) { // prevent recognizing touches on the slider return NO; } return YES; … Read more

How to programmatically trigger the touch event in android?

// Obtain MotionEvent object long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis() + 100; float x = 0.0f; float y = 0.0f; // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState() int metaState = 0; MotionEvent motionEvent = MotionEvent.obtain( downTime, eventTime, MotionEvent.ACTION_UP, x, y, metaState ); // Dispatch touch event to view view.dispatchTouchEvent(motionEvent);

Android Two finger rotation

Improvements of the class: angle returned is total since rotation has begun removing unnecessary functions simplification get position of first pointer only after second pointer is down public class RotationGestureDetector { private static final int INVALID_POINTER_ID = -1; private float fX, fY, sX, sY; private int ptrID1, ptrID2; private float mAngle; private OnRotationGestureListener mListener; public … Read more

How to detect Swipe Gesture in iOS?

If You know how it works, but still need a quick example, here it is! (it will become handy at least for me, when I will need copy-paste example, without trying remembering it) UISwipeGestureRecognizer *mSwipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething)]; [mSwipeUpRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)]; [[self view] addGestureRecognizer:mSwipeUpRecognizer]; and in .h file … Read more

In iOS, how to drag down to dismiss a modal?

I just created a tutorial for interactively dragging down a modal to dismiss it. http://www.thorntech.com/2016/02/ios-tutorial-close-modal-dragging/ I found this topic to be confusing at first, so the tutorial builds this out step-by-step. If you just want to run the code yourself, this is the repo: https://github.com/ThornTechPublic/InteractiveModal This is the approach I used: View Controller You override … Read more

Long press on UITableView

First add the long press gesture recognizer to the table view: UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; lpgr.minimumPressDuration = 2.0; //seconds lpgr.delegate = self; [self.myTableView addGestureRecognizer:lpgr]; [lpgr release]; Then in the gesture handler: -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer { CGPoint p = [gestureRecognizer locationInView:self.myTableView]; NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint:p]; if (indexPath == nil) { NSLog(@”long press on … Read more