Programmatically Created Swipe Event
-
20-12-2019 - |
Question
I would like to know how can I send a swipe gesture programmatically without actually swiping the phone. For instance, I have button that in the onClick
event I would call swipeGestureRecognizer
? Is this possible?
Solution
You can call the method you are calling on Swipe, when user taps on button. For examaple, you have a method for swipe gesture, call it onSwipe
. Now call onSwipe methos when user taps on the button. Thats it
EDIT
Here is the code for you:
-(void)myMethod{
//Write the logic you want to implement for swipe gesture here.
}
-(IBAction)onClick(UIButton *)sender{
[self myMethod];
}
-(IBAction)onSwipe:(UISwipeGestureRecognizer *)recognizer{
[self myMethod];
}
There might be bugs on the code as I am just typing the code using windows. Correct it for yourself in MAC & edit the answer too. it would definitely work for you
OTHER TIPS
If you need to pass the gesture event to the handler, then
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] init];
gesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self handleSwipe:gesture];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow