• 手势识别的 创建 与 方法


      /// 手势识别器

        // 1. 轻拍手势

        // 手势需要在定义是绑定一个触发方法(SEL)

    //    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

    //    

    //    // 轻拍的设置

    //    // 需要轻拍两次 才响应事件

    //    tap.numberOfTapsRequired = 2;

    //    // 需要几根手指 才响应事件

    //    tap.numberOfTouchesRequired = 2;

    //    // 给view添加一个手势

    //    [imageView addGestureRecognizer:tap];

    //    [tap release];

        

        

        

        // 2. 长按手势(longPress)

        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];

        // 长按 触发方法 需要时间

        longPress.minimumPressDuration = 2;

        // 长按时 允许用户移动手指的距离

        longPress.allowableMovement = 100;

        

        [imageView addGestureRecognizer:longPress];

        [longPress release];

        

        

        

        

        // 3. 清扫手势(swipe)

    //    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];

    //    // 设置清扫方向

    //    swipe.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;

    //    

    //    [imageView addGestureRecognizer:swipe];

    //    [swipe release];

        

        

        

        

    //    // 4.拖拽手势(pan)

    //    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];

    //    

    //    [imageView addGestureRecognizer:pan];

    //    [pan release];

    //    

    //    

    //    

    //    

    //    // 5.旋转(rotation)

    //    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];

    //    

    //    [imageView addGestureRecognizer:rotation];

    //    [rotation release];

    //    

    //    

    //    

    //    

    //    // 6. 捏合手势(pinch)

    //    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];

    //    

    //    [imageView addGestureRecognizer:pinch];

    //    [pinch release];

        

        

        

        // 7. 屏幕边缘的拖拽

        UIScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenPan:)];

        // 设置监测那一边的屏幕边缘

        screenEdgePan.edges = UIRectEdgeLeft;

        [imageView addGestureRecognizer:screenEdgePan];

        [screenEdgePan release];

        

        // 将UIImageView的用户交互打开,使它能响应轻拍

        [imageView setUserInteractionEnabled:YES];

    }

    - (void)screenPan:(UIScreenEdgePanGestureRecognizer *)screenPan

    {

        NSLog(@"边缘拖拽");

    }

    // 捏合的触发方法

    - (void)pinchAction:(UIPinchGestureRecognizer *)pinch

    {

        NSLog(@"捏合");

        // 获取当前的view

        UIImageView *imageView = (UIImageView *)pinch.view;

        // 在x,y轴方向 放大/缩小

        imageView.transform = CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale);

        pinch.scale = 1;  // 放大缩小的尺度(速度)

    }

    // 旋转方法

    - (void)rotationAction:(UIRotationGestureRecognizer *)rotation

    {

        NSLog(@"旋转");

        // 获取到当前手势添加到的view

        UIImageView *imageView = (UIImageView *)rotation.view;

        // 让view旋转 利用旋转手势的旋转弧度

        imageView.transform = CGAffineTransformRotate(imageView.transform, rotation.rotation);

        

        rotation.rotation = 0;

    }

    // 拖拽的触发方法

    - (void)panAction:(UIPanGestureRecognizer *)pan

    {

        NSLog(@"拖拽");

        // 通过手势的view属性 获取到当前手势添加到的 view

        UIImageView *imageview = (UIImageView *)pan.view;

        

        // 获取到当前手指接触的点

        CGPoint p = [pan translationInView:imageview];

        

        // 让view变形

        imageview.transform = CGAffineTransformTranslate(imageview.transform,p.x, p.y);

        

        // 重置手势的属性

        [pan setTranslation:CGPointZero inView:imageview];

    }

    // 清扫的触发方法

    - (void)swipeAction:(UISwipeGestureRecognizer *)swipe

    {

        NSLog(@"清扫");

    }

    // 轻拍的触发方法

    - (void)tapAction:(UITapGestureRecognizer *)tap

    {

        NSLog(@"轻拍");

        

    }

    // 长按的触发方法

    - (void)longPressAction:(UILongPressGestureRecognizer *)longPress

    {

        if (longPress.state == UIGestureRecognizerStateBegan) {

            NSLog(@"长按");

        }

    }

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    有人说:爱上一座城,是因为城里住着某个人,能够与所爱的人在一起,连光阴都是美的。即便粗茶淡饭,修篱种田,只要有你陪伴就好。那么,找一个青山绿水的地方,寻一处幽静的茅舍,或是云水禅心的庭院,那里有晴朗的阳光和静谧的悠然,还有你明媚的笑脸。掬一捧花香在平淡的日子,握着一路相随的暖意,让爱的馨香在柴米油盐中升腾;在一杯茶的温情里,体味生活的诗意;在一碗粥的清淡中,感受生活的浪漫,每天清晨你和阳光都在,便是我的幸福。——春暖花开 《择一城终老,遇一人白首》
  • 相关阅读:
    codeforces C. Fixing Typos 解题报告
    codeforces B. The Fibonacci Segment 解题报告
    codeforces B. Color the Fence 解题报告
    codeforces B. Petya and Staircases 解题报告
    codeforces A. Sereja and Bottles 解题报告
    codeforces B. Levko and Permutation 解题报告
    codeforces B.Fence 解题报告
    tmp
    API 设计 POSIX File API
    分布式跟踪的一个流行标准是OpenTracing API,该标准的一个流行实现是Jaeger项目。
  • 原文地址:https://www.cnblogs.com/-Eric-Liu/p/5563940.html
Copyright © 2020-2023  润新知