ios开发之手势处理 之手势识别一
#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开发之手势处理 之手势识别一的更多相关文章
- iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
-- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事 ...
- 转发:iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
-- iOS事件全面解析 转载来自崔江涛(KenshinCui) 链接:http://www.cnblogs.com/kenshincui/p/3950646.html 概览 iPhone的成功很大一 ...
- iOS开发-UITapGestureRecognizer手势
手势在iOS开发中是一个比较常用的功能,不过相对来说大家用的比较少,经常刷网易新闻,上次用了一下捏合手势才发现可以调整字体大小.昨天看到一个介绍摇一摇这个功能的,没看到之前一直都觉得摇一摇是微信的专有 ...
- 【转】 iOS开发之手势gesture详解
原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...
- iOS开发之手势gesture详解(二)
与其他用户界面控件交互 UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用 ...
- iOS开发之手势gesture详解(一)
前言 在iOS中,你可以使用系统内置的手势识别(GestureRecognizer),也可以创建自己的手势.GestureRecognizer将低级别的转换为高级别的执行行为,是你绑定到view的对象 ...
- iOS开发摇动手势实现详解
1.当设备摇动时,系统会算出加速计的值,并告知是否发生了摇动手势.系统只会运动开始和结束时通知你,并不会在运动发生的整个过程中始终向你报告每一次运动.例如,你快速摇动设备三次,那只会收到一个摇动事件. ...
- iOS开发 UIPanGestureRecognizer手势抽象类
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@sel ...
- iOS开发: 向右滑动手势功能实现
在navigationController中实现向右滑动 返回功能 系统提供的backbarbuttonitem,不用添加任何代码即可实现向右滑动后退功能,但是往往要对按钮修改样式等时,就需要自定义l ...
随机推荐
- BZOJ 3456 城市规划 ( NTT + 多项式求逆 )
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3456 题意: 求出\(n\)个点的简单(无重边无自环)无向连通图的个数.(\(n< ...
- 用VXE保护Linux系统安全
本文被转载在:http://www.linuxso.com/a/linuxxitongguanli/161.html 650) this.width=650;" onclick=&quo ...
- 高中生活-第9篇-开学之初的“失足”囧事,"刻舟求剑"导致腿折了
时间过得好快啊,上次发表"高中生活-第8篇:夏天的空调,冬天的味道"是2014年9月30日,一转眼,就是一年啊. 我自己以为,很多人可能都以为,我又半途而废了,实则不是哦~ 行百里 ...
- prettyJson V7.1 使用
头文件 #include "document.h" #include "prettywriter.h" #include "filereadstrea ...
- Direct2D 如何关闭抗锯齿
// Each pixel is rendered if its pixel center is contained by the geometry. // D2D1_ANTIALIAS_MODE_A ...
- 洛谷 P2677 超级书架 2
P2677 超级书架 2 题目描述 Farmer John最近为奶牛们的图书馆添置了一个巨大的书架,尽管它是如此的大,但它还是几乎瞬间就被各种各样的书塞满了.现在,只有书架的顶上还留有一点空间. 所有 ...
- 洛谷 P1610 鸿山洞的灯
P1610 鸿山洞的灯 题目描述 已知n盏灯以及每盏灯的位置p[i],p[i]均不相等,两盏相邻的灯当小于dist时,若这个安全距离里面还有灯是亮着时,就可以关掉该盏灯,(即若第i-1盏与第i+1盏的 ...
- 背景剪除和OpenCV中的实现
转载请注明出处! ! ! http://blog.csdn.net/zhonghuan1992 背景剪除和OpenCV中的实现 背景与前景都是相对的概念.以快速公路为例:有时我们对快速公路上来来往往的 ...
- Matrix学习——基础知识
以前在线性代数中学习了矩阵,对矩阵的基本运算有一些了解,前段时间在使用GDI+的时候再次学习如何使用矩阵来变化图像,看了之后在这里总结说明. 首先大家看看下面这个3 x 3的矩阵,这个矩阵被分割成4部 ...
- libcurl 通过http协议下载文件并显示下载进度
vc6 测试工程下载地址:http://download.csdn.net/detail/mtour/8068053 代码如下: size_t my_write_func(void *ptr, siz ...