zoukankan      html  css  js  c++  java
  • ios开发--旋转、移动、缩放手势实例代码

    // 添加所有的手势  

    • - (void) addGestureRecognizerToView:(UIView *)view  
    • {  
    •     // 旋转手势  
    •     UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateView:)];  
    •     [view addGestureRecognizer:rotationGestureRecognizer];  
    •       
    •     // 缩放手势  
    •     UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)];  
    •     [view addGestureRecognizer:pinchGestureRecognizer];  
    •       
    •     // 移动手势  
    •     UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)];  
    •     [view addGestureRecognizer:panGestureRecognizer];  
    • }  
    •   
    • // 处理旋转手势  
    • - (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];  
    •     }  
    • }  
    •   
    • // 处理缩放手势  
    • - (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];  
    •     }  
    • }  

    别忘了

    Java代码  
    1. [self addGestureRecognizerToView:view];  

    如果处理的是图片,别忘了

     
    C代码  
    1. [imageView setUserInteractionEnabled:YES];  
    2. [imageView setMultipleTouchEnabled:YES];  
  • 相关阅读:
    解决junit @RunWith无法使用的问题
    git .gitignore 有时不起作用的问题
    Docker常用命令 InsaneLoafer
    NOI2021 退役记
    2021“MINIEYE杯”中国大学生算法设计超级联赛 第二场 题解
    2021“MINIEYE杯”中国大学生算法设计超级联赛 第一场 题解
    数位DP
    Windows下Jmeter安装配置
    Linux安装docker-compose
    Ubuntu卸载MySQL
  • 原文地址:https://www.cnblogs.com/zhibin/p/4120993.html
Copyright © 2011-2022 走看看