zoukankan      html  css  js  c++  java
  • UI基础 手势

    root.m

    6大手势·

    #import "RootViewController.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        UIImageView *imageV=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 500)];
        imageV.image =[UIImage imageNamed:@"a.jpg"];
        [self.view addSubview:imageV];
       // 打开用户交互事件
        
        imageV.userInteractionEnabled=YES;
        //六大手势
        //1.点击手势
        //创建手势
        UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMe)];
        
        //控制点击次数
        tap.numberOfTapsRequired=3;
        
        //把手势添加到图片上
        [imageV addGestureRecognizer:tap];
        
        //2.长按手势
        UILongPressGestureRecognizer *longP=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPresssMe:)];
        //控制长按事件 (按多少秒触发)
        longP.minimumPressDuration=3;
        //控制长按过程中手指允许移动多少
        longP.allowableMovement=50;
        [imageV addGestureRecognizer:longP];
        
        
        //3.轻扫手势
        UISwipeGestureRecognizer* swip=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipMe:)];
        
        //指定方向
        swip.direction=UISwipeGestureRecognizerDirectionLeft;
        
        UISwipeGestureRecognizer* swip1=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipMe1:)];
        
        //指定方向
        swip.direction=UISwipeGestureRecognizerDirectionLeft;
        [imageV addGestureRecognizer:swip];
        
        
        //缩放手势
        UIPinchGestureRecognizer *pinch =[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchMe:)];
        
        
        [imageV addGestureRecognizer:pinch];
        
        //拖拽手势
        
        UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panMe:)];
        
        [imageV addGestureRecognizer:pan];
        
        //旋转手势
        UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationMe:)];
    
        [imageV addGestureRecognizer:rotation];
        
        //屏幕边界手势
    //    UIScreenEdgePanGestureRecognizer
        
    }
    //旋转手势对应方法
    -(void)rotationMe:(UIRotationGestureRecognizer *)rot
    {
        //获取手势所在视图
        UIImageView *imageV=(UIImageView *)rot.view;
        //矩阵变换
        imageV.transform=CGAffineTransformRotate(imageV.transform, rot.rotation);
        
        //重置旋转的弧度
        rot.rotation=0;
        
        
    }
    
    
    
    //拖拽手势对应方法
    -(void)panMe:(UIPanGestureRecognizer*)p
    {
        //获取手势所在视图
        UIImageView* imageV =(UIImageView *)p.view;
        //矩阵变化
        CGPoint point =[p translationInView:imageV];
        imageV.transform=CGAffineTransformTranslate(imageV.transform, point.x, point.y);
        //移动后的坐标
        [p setTranslation:CGPointZero inView:imageV];
        
        
    }
    
    
    
    
    //缩放手势对应方法
    -(void)pinchMe:(UIPinchGestureRecognizer *)pin
    {
        //获取手势所在的视图
        UIImageView* imageV =(UIImageView *)pin.view;
        //矩阵变换
        imageV.transform=CGAffineTransformScale(imageV.transform,pin.scale,pin.scale);
        
        //缩放比例参照最开始大小图片 若不加入 则会放大比例越来越大
        pin.scale=1;
        
        
    
        
    }
    
    
    //轻扫手势对应的方法
    -(void)swipMe:(UISwipeGestureRecognizer *)swipe
    {
        if(swipe.direction=UISwipeGestureRecognizerDirectionLeft)
        {
            NSLog(@"向左扫");
        }else if (swipe.direction==UISwipeGestureRecognizerDirectionDown)
        {
            NSLog(@"向下扫");
        }
    }
    
    
    
    
    
    //长按手势对应方法
    //想要实现什么功能 就可以写在哪个模块里
    -(void)longPresssMe:(UILongPressGestureRecognizer *)longPre
    {
        
        if(longPre.state==UIGestureRecognizerStateBegan){
            NSLog(@"开始");
        }else if (longPre.state==UIGestureRecognizerStateChanged){
            NSLog(@"手抖");
        }else if (longPre.state= UIGestureRecognizerStateEnded)
        {
            NSLog(@"结束");
        }
    }
    
    //点击手势对应的方法
    -(void)tapMe
    {
        NSLog(@"已打印");
        
    }
    
    @end
  • 相关阅读:
    Python3.x与Python2.x的区别
    Python3.x:打包为exe执行文件(window系统)
    Python3.x:常用基础语法
    关于yaha中文分词(将中文分词后,结合TfidfVectorizer变成向量)
    关于:cross_validation.scores
    list array解析(总算清楚一点了)
    pipeline(管道的连续应用)
    关于RandomizedSearchCV 和GridSearchCV(区别:参数个数的选择方式)
    VotingClassifier
    Python的zip函数
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13394309.html
Copyright © 2011-2022 走看看