美文网首页
UIImageView经过手势缩放、旋转之后如何还原

UIImageView经过手势缩放、旋转之后如何还原

作者: 不言弃zxf | 来源:发表于2020-07-29 15:46 被阅读0次

    // 处理缩放手势 

     - (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer 

     {      

    UIView *view = pinchGestureRecognizer.view;      

    if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) 

    {         

     view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);          pinchGestureRecognizer.scale = 1;     

     }  

    }  

     // 处理拖拉手势 

     - (void) panView:(UIPanGestureRecognizer *)panGestureRecognizer  

    {     

     UIView *view = panGestureRecognizer.view;   

       if (panGestureRecognizer.state == UIGestureRecognizerStateBegan || panGestureRecognizer.state == UIGestureRecognizerStateChanged)

     {         

     CGPoint translation = [panGestureRecognizer translationInView:view.superview];      

     [view setCenter:(CGPoint){view.center.x + translation.x, view.center.y + translation.y}];        

      [panGestureRecognizer setTranslation:CGPointZero inView:view.superview];      } 

     } 

     // 处理旋转手势  

    - (void) rotateView:(UIRotationGestureRecognizer *)rotationGestureRecognizer  {      

    UIView *view = rotationGestureRecognizer.view;    

      if (rotationGestureRecognizer.state == UIGestureRecognizerStateBegan || rotationGestureRecognizer.state == UIGestureRecognizerStateChanged) 

    {         

     view.transform = CGAffineTransformRotate(view.transform, rotationGestureRecognizer.rotation);         

     [rotationGestureRecognizer setRotation:0];     

     }  

    }    

    重点!!!在需要还原的地方写下这么一行代码,完美!!!

      imageView.transform = CGAffineTransformIdentity;

    相关文章

      网友评论

          本文标题:UIImageView经过手势缩放、旋转之后如何还原

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