UIPanGestureRecognizer方向判断(摘)
#pragma mark滑动手势的识别start
typedef enum:NSInteger{ kCameraMoveDirectionNone, kCameraMoveDirectionUp, kCameraMoveDirectionDown, kCameraMoveDirectionRight, kCameraMoveDirectionLeft }CameraMoveDirection;//枚举方向
-(void)panClick:(UIPanGestureRecognizer *) gesture{ CGPoint translation = [gesture translationInView:self];//最后会有这个方法的说明 if(gesture.state ==UIGestureRecognizerStateBegan) { direction = kCameraMoveDirectionNone; } else if(gesture.state ==UIGestureRecognizerStateChanged&& direction == kCameraMoveDirectionNone) { direction = [self determineCameraDirectionIfNeeded:translation];//方向函数//方向参数是上面定义的那个枚举类型 // ok, now initiate movement in the direction indicated by the user's gesture switch(direction) { case kCameraMoveDirectionDown:{ NSLog(@"Start moving down");break; } case kCameraMoveDirectionUp:{ NSLog(@"Start moving up");break; } case kCameraMoveDirectionRight: NSLog(@"Start moving right"); //和左右滑动的按钮功能搬到这里来break; case kCameraMoveDirectionLeft: NSLog(@"Start moving left");break; default: break; } } else if(gesture.state ==UIGestureRecognizerStateEnded) { // now tell the camera to stop NSLog(@"Stop"); } }
CGFloat const gestureMinimumTranslation=20.0;//最小形变的决定吧 - (CameraMoveDirection)determineCameraDirectionIfNeeded:(CGPoint)translation { if(direction != kCameraMoveDirectionNone) return direction; // determine if horizontal swipe only if you meet some minimum velocity if(fabs(translation.x) > gestureMinimumTranslation) { BOOL gestureHorizontal = NO; if(translation.y ==0.0) gestureHorizontal = YES; else gestureHorizontal = (fabs(translation.x / translation.y) >5.0); if(gestureHorizontal) { if(translation.x >0.0) return kCameraMoveDirectionRight; else return kCameraMoveDirectionLeft; } } // determine if vertical swipe only if you meet some minimum velocity else if(fabs(translation.y) > gestureMinimumTranslation) { BOOL gestureVertical = NO; if(translation.x ==0.0) gestureVertical = YES; else gestureVertical = (fabs(translation.y / translation.x) >5.0); if(gestureVertical) { if(translation.y >0.0) return kCameraMoveDirectionDown; else return kCameraMoveDirectionUp; } } return direction; }
CGPoint location = [sender locationInView:self.view]; CGPoint translation; translation.x = location.x - viewStartLocation.x; translation.y = location.y - viewStartLocation.y;//2个函数的区别,一个坐标,一个是形变量
//这个方法用在了那个日历的插件里面
1.这里只记录一些学习笔记
2.这里只记录一些学习心得,如果心得方向有错,请留言
2.这里只记录一些日记(只为提升英语,暂时有点忙,等转行了开始写)