zoukankan      html  css  js  c++  java
  • 六种手势

    1.点击

    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGR:)];

        tapGes.numberOfTouchesRequired = 1;

        tapGes.numberOfTapsRequired = 2;

        [self.view addGestureRecognizer:tapGes];

      

    - (void)tapGR:(UIGestureRecognizer *)Gesture{

        NSLog(@"点击手势");

        UIView *v = Gesture.view;

        

        v.backgroundColor = [UIColor greenColor];

        

        

    }

     

    2.拖拽

        UIPanGestureRecognizer *panGes = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panView:)];  

        [_panView addGestureRecognizer:panGes];

    }

    - (void)panView:(UIGestureRecognizer *)Gesture{

        NSLog(@"pan");

        CGPoint viewP;

        CGPoint panP;

        if (Gesture.state == UIGestureRecognizerStateBegan) {

            viewP = _panView.center;

            panP  = [Gesture locationInView:self.view];

            

        }

        

        CGPoint nowP = [Gesture locationInView:self.view];

        float x = nowP.x - panP.x;

        float y = nowP.y - panP.y;

        

        _panView.center = CGPointMake(viewP.x + x, viewP.y + y);

        

    }

    3.轻扫

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

    //    swipeGes.numberOfTouchesRequired = 1;//几个手指

    //    swipeGes.direction = UISwipeGestureRecognizerDirectionUp;

    //    [self.view addGestureRecognizer:swipeGes];

        

        //四个方向的手势

        for (int i = 0; i<4; i++) {

            UISwipeGestureRecognizer *swipeGes = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGR:)];

            swipeGes.numberOfTouchesRequired = 1;//几个手指

            swipeGes.direction = 1<<i;

            [self.view addGestureRecognizer:swipeGes];

            

        }

        

    }

     

    - (void)swipeGR:(UISwipeGestureRecognizer *)gesture{

        NSLog(@"swipe");

        NSInteger dir = gesture.direction;

        NSString *str;

        if (dir == 1<<0 ? str = @"向上": @"") {

            NSLog(@"%@",str);

        }

        

    }

    4.长按

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

        

        longGes.minimumPressDuration = 1;

        

        [self.view addGestureRecognizer:longGes];

    }

    - (void)longGes:(UIGestureRecognizer *)gesture{

        

        NSLog(@"longpress");

    }

    5.旋转

      UIRotationGestureRecognizer *rotationGes = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationGes:)];

        

        

        [self.view addGestureRecognizer:rotationGes];

        

    }

     

    //

    - (void)rotationGes:(UIRotationGestureRecognizer *)gesture{

        NSLog(@"rotaiton");

        static CGFloat startRot;

        

        self.view.transform = CGAffineTransformMakeRotation(gesture.rotation + startRot);

     

        if (gesture.state == UIGestureRecognizerStateEnded) {

            startRot += gesture.rotation;

        }

        

     

    }

    6.捏合(放大/缩小)

      UIPinchGestureRecognizer *pinchGes = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGes:)];

        

        [self.view addGestureRecognizer:pinchGes];

        

    }

    - (void)pinchGes:(UIPinchGestureRecognizer *)gesture{

        NSLog(@"pinch");

        static CGFloat startScale = 1;

        

        self.view.transform = CGAffineTransformMakeScale(gesture.scale * startScale, gesture.scale * startScale);

        

        if (gesture.state == UIGestureRecognizerStateEnded) {

            startScale *= gesture.scale;

        }

        

    }

  • 相关阅读:
    大数据技术之Kafka是什么
    大数据技术之Hadoop 基础认识
    在eclipse中运行Mapreduce & spark
    datatstage 中一直处于Ready 状态
    Datastage run 有时候太慢 有时候performance 还Okay
    不能重复造轮子,尤其是枯燥的轮子,要造就造有趣的、好玩的轮子
    什么是好?什么是优秀?
    字面量-上集
    图片切换-vue
    数据绑定
  • 原文地址:https://www.cnblogs.com/daxueshan/p/5815440.html
Copyright © 2011-2022 走看看