美文网首页
UIPinchGestureRecognizer捏合手势

UIPinchGestureRecognizer捏合手势

作者: 浅_若清风 | 来源:发表于2018-06-01 14:00 被阅读0次

    概述:UIPinchGestureRecognizer捏合手势,继承于UIGestureRecognizer类,相对于UIGestureRecognizer多了两个属性值。

     /*获取缩放(捏合)的大小*/
    @property (nonatomic)          CGFloat scale; 
     /*获取缩放(捏合)的速度*/
    @property (nonatomic,readonly) CGFloat velocity;  
    

    案例:图片的放大缩小

     UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureDetected:)];
     [pinchGestureRecognizer setDelegate:self];
    /*加载到要缩放的图片*/
     [self.image_view addGestureRecognizer:pinchGestureRecognizer];
    
    - (void)pinchGestureDetected:(UIPinchGestureRecognizer *)recognizer{
         /*获取状态*/
        UIGestureRecognizerState state = [recognizer state];
        if (state == UIGestureRecognizerStateBegan || state == UIGestureRecognizerStateChanged){
           /*获取捏合大小比例*/
           CGFloat scale = [recognizer scale];
           /*获取捏合的速度*/
           CGFloat velocity = [recognizer velocity];
           NSLog(@"velocity %f",velocity);
           [recognizer.view setTransform:CGAffineTransformScale(recognizer.view.transform, scale, scale)];
           [recognizer setScale:1.0];
           if (self.image_view.frame.size.width <= self.view.bounds.size.width) {
                self.image_view.frame = self.view.bounds;
           }
        }
    }
    

    注:了解UIGestureRecognizer类请跳转https://www.jianshu.com/p/e206dc86f89a

    相关文章

      网友评论

          本文标题:UIPinchGestureRecognizer捏合手势

          本文链接:https://www.haomeiwen.com/subject/bujajftx.html