zoukankan      html  css  js  c++  java
  • 手势(5)——利用GestureRecognizer

    #import "MJmainViewController.h"

    @interface MJmainViewController ()

    @end

    @implementation MJmainViewController

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }


    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        self.title=@"UITapGestureRecognizer";
        self.view.backgroundColor=[UIColor greenColor];
        
        //============= 轻拍==============
        UITapGestureRecognizer *onefinger=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onetap:)];
        onefinger.numberOfTapsRequired=1;
        onefinger.numberOfTouchesRequired=1;
        [self.view addGestureRecognizer:onefinger];
        
        
        UITapGestureRecognizer *doublefinger=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(twotap:)];
        
        doublefinger.numberOfTapsRequired=2;
        doublefinger.numberOfTouchesRequired=1;
        [self.view addGestureRecognizer:doublefinger];
        [onefinger  requireGestureRecognizerToFail:doublefinger];
        
        
        //==============缩放=============
        UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(onPinch:)];
        
        [self.view addGestureRecognizer:pinch];
        
        
        //===============拖拽=============
    #if 1
        UIPanGestureRecognizer *pan =[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(onPan:)];
        pan.maximumNumberOfTouches=2;
        pan.minimumNumberOfTouches=1;
        [self.view addGestureRecognizer:pan];
    #endif
        
        //===============横扫=============
        UISwipeGestureRecognizer *swiperight =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(onSwipe:)];
        swiperight.direction=UISwipeGestureRecognizerDirectionRight;
        [self.view addGestureRecognizer:swiperight];
        
        UISwipeGestureRecognizer *swipeleft =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(onSwipe:)];
        swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:swipeleft];
        
        UISwipeGestureRecognizer *swipeup =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(onSwipe:)];
        swipeup.direction=UISwipeGestureRecognizerDirectionUp;
        [self.view addGestureRecognizer:swipeup];
        
        UISwipeGestureRecognizer *swipedown =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(onSwipe:)];
        swipedown.direction=UISwipeGestureRecognizerDirectionDown;
        [self.view addGestureRecognizer:swipedown];
        
        [pan requireGestureRecognizerToFail:swiperight];
        [pan requireGestureRecognizerToFail:swipeleft];
        [pan requireGestureRecognizerToFail:swipeup];
        [pan requireGestureRecognizerToFail:swipedown];

       //===================旋转=================
        UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(onRatation:)];
        [self.view addGestureRecognizer:rotation];
        

        

    //  ====================边界拖入界面==================
        UIScreenEdgePanGestureRecognizer *screenleft =[[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(onscreen:)];
        screenleft.edges=UIRectEdgeLeft;
        [self.view addGestureRecognizer:screenleft];
        
        UIScreenEdgePanGestureRecognizer *screenfight =[[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(onscreen:)];
        screenfight.edges=UIRectEdgeRight;
        [self.view addGestureRecognizer:screenfight];
        
        [swiperight requireGestureRecognizerToFail:screenleft];
        

        
        //  ====================长摁===================
        UILongPressGestureRecognizer *longpress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(onLongPress:)];
        longpress.numberOfTouchesRequired=1;
        [self.view addGestureRecognizer:longpress];
        
        
        
        [onefinger requireGestureRecognizerToFail:longpress];
        

        
        
    }





    -(void)onetap:(UITapGestureRecognizer *)sender
    {
        NSLog(@"单击");
    }



    -(void)twotap:(UITapGestureRecognizer *)sender
    {
        NSLog(@"双击");
    }



    -(void)onPinch:(UIPinchGestureRecognizer *)sender
    {
        if (sender.scale>1) {
            NSLog(@"放大");
        }else{
            NSLog(@"缩放");}
    }

    -(void)onPan:(UIPanGestureRecognizer *)sender
    {
        NSLog(@"拖拽");
    }

    -(void)onSwipe:(UISwipeGestureRecognizer *)sender
    {
        
        if (sender.direction == UISwipeGestureRecognizerDirectionRight) {
            
            NSLog(@"右扫");
        }else{
            if ( sender.direction==UISwipeGestureRecognizerDirectionLeft) {
                NSLog(@"左扫");
            }else{
                if (sender.direction==UISwipeGestureRecognizerDirectionUp ) {
                    NSLog(@"向上扫");
                    
                }else{
                    NSLog(@"向下扫");
                    
                }
            }
            
        }
    }

    -(void)onRatation:(UIRotationGestureRecognizer *)sender
    {
        NSLog(@"%f",sender.rotation);
        
       
    }

    -(void)onscreen:(UIScreenEdgePanGestureRecognizer *)sender
    {
        if (sender.edges==UIRectEdgeLeft) {
            NSLog(@"左边的妹妹快出来");
        }else{
        NSLog(@"右边的妹妹快出来");
        }
    }


    -(void)onLongPress:(UILongPressGestureRecognizer *)sender
    {
        NSLog(@"长摁");
    }

    @end

  • 相关阅读:
    day91:luffy:基于vue+drf的路飞学城项目后端部署
    day90:luffy:基于vue+drf的路飞学城项目前端部署
    day89:luffy:使用Celery完成我的订单超时取消&Polyv视频加密播放
    day88:luffy:支付宝同步结果通知&接收异步支付结果&用户购买记录&我的订单
    day87:luffy:结算页面积分&支付宝接口
    day86:luffy:前端发送请求生成订单&结算页面优惠劵的实现
    day85:luffy:购物车根据有效期不同切换价格&购物车删除操作&价格结算&订单页面前戏
    C++中子类出现与父类同名成员函数如果调用父类函数
    C++继承方式引起子类中继承的父类属性访问权限的改变 && C++对象大小
    C++引用传递和指针传递区别
  • 原文地址:https://www.cnblogs.com/wangdelong/p/3848575.html
Copyright © 2011-2022 走看看