#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *imageV; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; //1.创建手势
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
//设置轻扫的方向(一个轻扫手势只能对应一个方向)
swipe.direction = UISwipeGestureRecognizerDirectionLeft; UISwipeGestureRecognizer *swipe1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
//设置轻扫的方向(一个轻扫手势只能对应一个方向)
swipe1.direction = UISwipeGestureRecognizerDirectionRight; //2.添加手势
[self.imageV addGestureRecognizer:swipe];
[self.imageV addGestureRecognizer:swipe1];
} //当轻扫时调用
- (void)swipe:(UISwipeGestureRecognizer *)swipe{ if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"left");
}else if(swipe.direction == UISwipeGestureRecognizerDirectionRight){
NSLog(@"right");
} //NSLog(@"%s",__func__);
} //长按手势
- (void)longP{
//1.创建手势
UILongPressGestureRecognizer *longP = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longP:)]; //2.添加手势
[self.imageV addGestureRecognizer:longP];
} //当长按时调用(当长按移动时,该方法会持续调用)
- (void)longP:(UILongPressGestureRecognizer *)longP{
NSLog(@"%s",__func__);
//判断手势的状态
if (longP.state == UIGestureRecognizerStateBegan) {
NSLog(@"开始长按");
}else if(longP.state == UIGestureRecognizerStateChanged){
NSLog(@"长按时移动");
}else if(longP.state == UIGestureRecognizerStateEnded){
NSLog(@"手指离开");
} } //点按手势
- (void)setUpTap{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]; tap.delegate = self; //2.添加手势
[self.imageV addGestureRecognizer:tap]; } //3.实现手势方法
- (void)tap{ NSLog(@"%s",__func__);
} //是否允许接收手指.
//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { //让当前的图片,左边不能点击 ,右边能够点击
//获取当前手指的点
// CGPoint curP = [touch locationInView:self.imageV];
//
// if (curP.x > self.imageV.frame.size.width * 0.5) {
// //在右边
// return YES;
// }else{
// //在左边
// return NO;
// }
//
//
//} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

ios开发之手势处理 之手势识别一的更多相关文章

  1. iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控

    -- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事 ...

  2. 转发:iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控

    -- iOS事件全面解析 转载来自崔江涛(KenshinCui) 链接:http://www.cnblogs.com/kenshincui/p/3950646.html 概览 iPhone的成功很大一 ...

  3. iOS开发-UITapGestureRecognizer手势

    手势在iOS开发中是一个比较常用的功能,不过相对来说大家用的比较少,经常刷网易新闻,上次用了一下捏合手势才发现可以调整字体大小.昨天看到一个介绍摇一摇这个功能的,没看到之前一直都觉得摇一摇是微信的专有 ...

  4. 【转】 iOS开发之手势gesture详解

    原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...

  5. iOS开发之手势gesture详解(二)

    与其他用户界面控件交互 UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用 ...

  6. iOS开发之手势gesture详解(一)

    前言 在iOS中,你可以使用系统内置的手势识别(GestureRecognizer),也可以创建自己的手势.GestureRecognizer将低级别的转换为高级别的执行行为,是你绑定到view的对象 ...

  7. iOS开发摇动手势实现详解

    1.当设备摇动时,系统会算出加速计的值,并告知是否发生了摇动手势.系统只会运动开始和结束时通知你,并不会在运动发生的整个过程中始终向你报告每一次运动.例如,你快速摇动设备三次,那只会收到一个摇动事件. ...

  8. iOS开发 UIPanGestureRecognizer手势抽象类

    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@sel ...

  9. iOS开发: 向右滑动手势功能实现

    在navigationController中实现向右滑动 返回功能 系统提供的backbarbuttonitem,不用添加任何代码即可实现向右滑动后退功能,但是往往要对按钮修改样式等时,就需要自定义l ...

随机推荐

  1. 1.lombok系列1:初识lombok

    转自:https://www.imooc.com/article/18156 初识lombok 官网:https://projectlombok.org/ 什么是lombok 连官网都懒得废话,只给出 ...

  2. the resource is not on the build path of a java project错误

    在eclipse中,使用mavenimport了一个工程,但是在对某一个类进行F3/F4/ctrl+alt+H操作的时候报错:“the resource is not on the build pat ...

  3. ByteUtils

    package sort.bing.com; import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import j ...

  4. android组件

    SlidingDrawer http://www.cnblogs.com/renyuan/archive/2012/09/16/2687929.html autocompletetextview  / ...

  5. CODEVS——T1519 过路费

    http://codevs.cn/problem/1519/ 时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master 题解  查看运行结果     题目描述 Desc ...

  6. R语言-有负下标里才干有零

    1.仅仅有负下标里才干有零 先看一个样例 >a<-c(1,2,3,4) >a[-1:1] > a[-1:1] Error in a[-1:1] : 仅仅有负下标里才干有零 (1 ...

  7. 24.C语言最全排序方法小结(不断更新)

    希尔排序: 该方法的基本思想是:先将整个待排元素序列切割成若干个子序列(由相隔某个“增量”的元素组成的)分别进行直接插入排序,然后依次缩减增量再进行排序,待整个序列中的元素基本有序(增量足够小)时,再 ...

  8. JavaScript篇(一)二叉树的插入 (附:可视化)

    一.二叉树概念 二叉树(binary tree)是一颗树,其中每个节点都不能有多于两个的儿子. 字节一面,第一道就是二叉树的插入,在这里其实是对于一个二叉查找树的插入. 使二叉树成为二叉查找树的性质是 ...

  9. Docker---(2)为什么要用Docker

    原文:Docker---(2)为什么要用Docker 版权声明:欢迎转载,请标明出处,如有问题,欢迎指正!谢谢!微信:w1186355422 https://blog.csdn.net/weixin_ ...

  10. 【习题 6-8 UVA - 806】Spatial Structures

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写两个dfs模拟就好. 注意每12个数字输出一个换行.. [代码] /* 1.Shoud it use long long ? 2. ...