How to recognize swipe in all 4 directions?

前端 未结 8 472
后悔当初
后悔当初 2020-12-03 01:00

I need to recognize swipes in all directions (Up/Down/Left/Right). Not simultaneously, but I need to recognize them.

I tried:

  UISw         


        
8条回答
  •  无人及你
    2020-12-03 01:47

    You can add only one diagonal by SwipeGesture, then...

        UISwipeGestureRecognizer *swipeV = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(action)];
        UISwipeGestureRecognizer *swipeH = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(action)];
        swipeH.direction = ( UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight  );
        swipeV.direction = ( UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown );
        [self addGestureRecognizer:swipeH];
        [self addGestureRecognizer:swipeV];
         self.userInteractionEnabled = YES;
    

提交回复
热议问题