How to detect Swipe Gesture in iOS?

前端 未结 3 473
时光取名叫无心
时光取名叫无心 2020-11-28 07:20

In my iPhone app, I require to recognize the swipe gesture made by the user on the view.

I want the swipe gestures to be recognized and perform a function on swipe.<

3条回答
  •  醉话见心
    2020-11-28 08:05

    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 add:

    
    

提交回复
热议问题