Created
December 16, 2014 01:47
-
-
Save sonsongithub/e17116d8cba09d12c3ae to your computer and use it in GitHub Desktop.
detect direction of UIKIt gesture recognizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { | |
// スワイプのジェスチャを開始するかを判定する | |
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { | |
UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gestureRecognizer; | |
CGPoint velocity = [panGesture velocityInView:panGesture.view]; | |
double radian = atan(velocity.y/velocity.x); | |
double degree = radian * 180 / M_PI; | |
// 指定した角度よりも大きく(斜めに)スワイプした場合は,ジェスチャは開始されない | |
if (fabs(degree) > SwipeDirectionThreadholdAsDegree) { | |
return NO; | |
} | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment