• 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个函数的区别,一个坐标,一个是形变量

    //这个方法用在了那个日历的插件里面

  • 相关阅读:
    webpack中optimization 的 runtimeChunk 是干嘛的
    快速排序
    域名解析的设置
    MingW和cygwin的区别(转)
    设计模式总结
    OPTIONS请求 简单请求与 非简单请求
    axios的坑
    idea+maven+springboot+mybatis+springmvc+shiro
    Shiro 自定义角色 认证
    spring+shiro+springmvc+maven权限卡控示例
  • 原文地址:https://www.cnblogs.com/liyang31tg/p/4133747.html
Copyright © 2020-2023  润新知