zoukankan      html  css  js  c++  java
  • IOS 长按+轻扫(手势识别)

    @interface NJViewController ()
    @property (weak, nonatomic) IBOutlet UIView *customView;
    
    @end
    
    @implementation NJViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        // 向上
        UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] init];
        // 设置轻扫的方向
        swipe.direction = UISwipeGestureRecognizerDirectionUp;
        [self.customView addGestureRecognizer:swipe];
        [swipe addTarget:self action:@selector(swipeView)];
        
        // 向下
        UISwipeGestureRecognizer *swipe2 = [[UISwipeGestureRecognizer alloc] init];
        // 设置轻扫的方向
        swipe2.direction = UISwipeGestureRecognizerDirectionDown;
        [self.customView addGestureRecognizer:swipe2];
        [swipe2 addTarget:self action:@selector(swipeView2)];
        
        // 左边
        UISwipeGestureRecognizer *swipe3 = [[UISwipeGestureRecognizer alloc] init];
        // 设置轻扫的方向
        swipe3.direction = UISwipeGestureRecognizerDirectionLeft;
        [self.customView addGestureRecognizer:swipe3];
        [swipe3 addTarget:self action:@selector(swipeView3)];
        
        // 右边
        UISwipeGestureRecognizer *swipe4 = [[UISwipeGestureRecognizer alloc] init];
        // 设置轻扫的方向
        swipe4.direction = UISwipeGestureRecognizerDirectionRight;
        [self.customView addGestureRecognizer:swipe4];
        [swipe4 addTarget:self action:@selector(swipeView4)];
        
        
        
    }
    - (void)swipeView4
    {
        NSLog(@"轻扫事件右");
    }
    
    - (void)swipeView3
    {
        NSLog(@"轻扫事件左");
    }
    
    - (void)swipeView2
    {
        NSLog(@"轻扫事件下");
    }
    
    - (void)swipeView
    {
        NSLog(@"轻扫事件上");
    }
    
    - (void)test
    {
        // 长按事件
        // 1.创建手势识别器
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] init];
        // 1.1设置长按手势识别器的属性
        //    longPress.minimumPressDuration = 5;
        
        // 手指按下后事件响应之前允许手指移动的偏移位
        longPress.allowableMovement = 50;
        
        
        // 2.添加手势识别器到View
        [self.customView addGestureRecognizer:longPress];
        
        // 3.监听手势识别器
        [longPress addTarget:self action:@selector(longPressView)];
    }
    
     -(void)longPressView
    {
        NSLog(@"长按事件");
    }
    
    @end
  • 相关阅读:
    10.14 正睿做题笔记
    斯坦纳树
    django+uwsgi+nginx 前后端分离部署配置
    pandas 取 groupby 后每个分组的前 N 行
    使用 Java SDK 获取 MaxCompute 的表结构并写入到 Excel 中
    PPYOLO模型参数配置理解
    分子表面计算库MSMS的linux安装教程
    使用Python的seaborn画热力图heatmap以及将两个矩阵合并画热图的方法
    常见图片格式分析-bmp,png
    BUUOJ-Misc刷题笔记
  • 原文地址:https://www.cnblogs.com/liuwj/p/6599260.html
Copyright © 2011-2022 走看看