• ios开发--旋转、移动、缩放手势实例代码


    1. // 添加所有的手势  
    2. - (void) addGestureRecognizerToView:(UIView *)view  
    3. {  
    4.     // 旋转手势  
    5.     UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateView:)];  
    6.     [view addGestureRecognizer:rotationGestureRecognizer];  
    7.       
    8.     // 缩放手势  
    9.     UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)];  
    10.     [view addGestureRecognizer:pinchGestureRecognizer];  
    11.       
    12.     // 移动手势  
    13.     UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)];  
    14.     [view addGestureRecognizer:panGestureRecognizer];  
    15. }  
    16.   
    17. // 处理旋转手势  
    18. - (void) rotateView:(UIRotationGestureRecognizer *)rotationGestureRecognizer  
    19. {  
    20.     UIView *view = rotationGestureRecognizer.view;  
    21.     if (rotationGestureRecognizer.state == UIGestureRecognizerStateBegan || rotationGestureRecognizer.state == UIGestureRecognizerStateChanged) {  
    22.         view.transform = CGAffineTransformRotate(view.transform, rotationGestureRecognizer.rotation);  
    23.         [rotationGestureRecognizer setRotation:0];  
    24.     }  
    25. }  
    26.   
    27. // 处理缩放手势  
    28. - (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer  
    29. {  
    30.     UIView *view = pinchGestureRecognizer.view;  
    31.     if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {  
    32.         view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);  
    33.         pinchGestureRecognizer.scale = 1;  
    34.     }  
    35. }  
    36.   
    37. // 处理拖拉手势  
    38. - (void) panView:(UIPanGestureRecognizer *)panGestureRecognizer  
    39. {  
    40.     UIView *view = panGestureRecognizer.view;  
    41.     if (panGestureRecognizer.state == UIGestureRecognizerStateBegan || panGestureRecognizer.state == UIGestureRecognizerStateChanged) {  
    42.         CGPoint translation = [panGestureRecognizer translationInView:view.superview];  
    43.         [view setCenter:(CGPoint){view.center.x + translation.x, view.center.y + translation.y}];  
    44.         [panGestureRecognizer setTranslation:CGPointZero inView:view.superview];  
    45.     }  
    46. }  
  • 相关阅读:
    导出CSV乱码
    php让一个数组按照另外一个数组的键名进行排序
    电脑没有网
    Android抓包方法(转)
    封装curl的get和post请求
    JavaScript动态加载CSS和JS文件
    压缩视频之后网页上只有声音,没有图像
    php BCMath高精度计算
    非table结构数据导入excel
    如何将页面上的数据导入excel中
  • 原文地址:https://www.cnblogs.com/swallow37/p/3836362.html
Copyright © 2020-2023  润新知