iOS---给视图添加手势

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
初始化手势同时添加手势事件---把手势添加到视图上 // 1.轻拍手势类
    // 创建一个轻拍手势 同时绑定了一个事件
    UITapGestureRecognizer *aTapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)];
    // 设置轻拍次数
    aTapGR.numberOfTapsRequired = 1;
     
    // 设置手指触摸的个数
    aTapGR.numberOfTouchesRequired = 2;
     
    // 添加手势
    [self.rootView addGestureRecognizer:aTapGR];
    [aTapGR release];
    
     
    // 2.长按手势
  UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
     
    [self.rootView addGestureRecognizer:longPressGR];
    [longPressGR release];
  
    // 3.旋转手势
    UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];
    [self.rootView.testImageView addGestureRecognizer:rotationGR];
    [rotationGR release];
    
    // 4.捏合手势
 UIPinchGestureRecognizer *pinchRG = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
    [self.rootView addGestureRecognizer:pinchRG];
    [pinchRG release];
   
    // 5.平移手势
     
UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGRAction:)];
    [self.rootView.testImageView addGestureRecognizer:panGR];
    [panGR release];
 
    // 6.轻扫手势
UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGRAction:)];
     
    // 设置滑动方向 默认是从左往右
    swipeGR.direction = UISwipeGestureRecognizerDirectionLeft; // 设置向左滑动
     
    [self.rootView.testImageView addGestureRecognizer:swipeGR];
    [swipeGR release];
 
    // 7.屏幕边缘轻扫识别器
 
    UIScreenEdgePanGestureRecognizer *screenPGR = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgeGRAction:)];
    [self.rootView addGestureRecognizer:screenPGR];
    [screenPGR release];

 

posted @   百川hl  阅读(4560)  评论(0编辑  收藏  举报
编辑推荐:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示