Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created December 16, 2014 01:47
Show Gist options
  • Save sonsongithub/e17116d8cba09d12c3ae to your computer and use it in GitHub Desktop.
Save sonsongithub/e17116d8cba09d12c3ae to your computer and use it in GitHub Desktop.
detect direction of UIKIt gesture recognizer
- (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