iOS开发之手势识别汇总

iOS开发中手势识别有六种:

轻击手势(TapGestureRecognizer),

轻扫手势 (SwipeGestureRecognizer),

长按手势(LongPressGestureRecognizer),

拖动手势(PanGestureRecognizer),

捏合手势(PinchGestureRecognizer),

旋转手势(RotationGestureRecognizer),

1,轻击手势(TapGestureRecognizer)

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
tapGesture.numberOfTapsRequired = 1; //点击次数
tapGesture.numberOfTouchesRequired = 1; //点击手指数
[self.view addGestureRecognizer:tapGesture]; //轻击手势触发方法
-(void)tapGesture:(UITapGestureRecognizer *)sender
{
//your code
}

2,长按手势(LongPressGestureRecognizer)

UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGesture:)];
//设置长按时间
longPressGesture.minimumPressDuration = 0.5;
[self.view addGestureRecognizer:longPressGesture]; //长按手势触发方法
-(void)longPressGesture:(id)sender
{
UILongPressGestureRecognizer *longPress = sender;
if (longPress.state == UIGestureRecognizerStateBegan)
{
//your code
}
} 说明:长按手势的常用状态如下 开始:UIGestureRecognizerStateBegan 改变:UIGestureRecognizerStateChanged 结束:UIGestureRecognizerStateEnded 取消:UIGestureRecognizerStateCancelled 失败:UIGestureRecognizerStateFailed

3,轻扫手势(SwipeGestureRecognizer)

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
//设置轻扫的方向
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; //向右
[self.view addGestureRecognizer:swipeGesture]; UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
//设置轻扫的方向
swipeGestureLeft.direction = UISwipeGestureRecognizerDirectionLeft; //向左
[self.view addGestureRecognizer:swipeGestureLeft]; //轻扫手势触发方法
-(void)swipeGesture:(id)sender
{ UISwipeGestureRecognizer *swipe = sender; if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
{
//向左轻扫
} if (swipe.direction == UISwipeGestureRecognizerDirectionRight)
{
//向右轻扫
}
}

4,捏合手势(PinchGestureRecognizer)

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
[self.view addGestureRecognizer:pinchGesture]; ////捏合手势触发方法
-(void) pinchGesture:(id)sender
{
UIPinchGestureRecognizer *gesture = sender;
//手势改变时
if (gesture.state == UIGestureRecognizerStateChanged)
{
//捏合手势中scale属性记录的缩放比例
_imageView.transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale);
} //结束后恢复
if(gesture.state==UIGestureRecognizerStateEnded)
{
[UIView animateWithDuration:0.5 animations:^{
_imageView.transform = CGAffineTransformIdentity;//取消一切形变
}];
}
}

5,拖动手势(PanGestureRecognizer)

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[self.view addGestureRecognizer:panGesture]; //拖动手势触发方法
-(void) panGesture:(id)sender
{
UIPanGestureRecognizer *panGesture = sender;
CGPoint movePoint = [panGesture translationInView:self.view];
//your code
}

6,旋转手势(RotationGestureRecognizer)

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
[self.view addGestureRecognizer:rotationGesture]; //旋转手势触发方法
-(void)rotationGesture:(id)sender
{
UIRotationGestureRecognizer *gesture = sender;
if (gesture.state==UIGestureRecognizerStateChanged)
{
_imageView.transform=CGAffineTransformMakeRotation(gesture.rotation);
}
if(gesture.state==UIGestureRecognizerStateEnded)
{
[UIView animateWithDuration:1 animations:^{
_imageView.transform=CGAffineTransformIdentity;//取消形变
}];
}
}

本文出处刚刚在线:http://www.superqq.com/blog/2015/01/14/ioskai-fa-zhi-shou-shi-shi-bie-hui-zong/

iOS开发之手势识别汇总的更多相关文章

  1. iOS开发之手势识别

    感觉有必要把iOS开发中的手势识别做一个小小的总结.在上一篇iOS开发之自定义表情键盘(组件封装与自动布局)博客中用到了一个轻击手势,就是在轻击TextView时从表情键盘回到系统键盘,在TextVi ...

  2. [转载]iOS开发之手势识别

    感觉有必要把iOS开发中的手势识别做一个小小的总结.在上一篇iOS开发之自定义表情键盘(组件封装与自动布局)博客中用到了一个轻击手势,就是在轻击TextView时从表情键盘回到系统键盘,在TextVi ...

  3. iOS开发学习网站汇总

    *本文转自CocoaChina 原文:11 Insanely Great iOS Developers Sites永不止步地向他人学习 我相信,要想从一个"还不错"的人变成一个卓越 ...

  4. iOS开发中六种手势识别

    iOS开发中手势识别有六种: 轻击手势(TapGestureRecognizer), 轻扫手势 (SwipeGestureRecognizer), 长按手势(LongPressGestureRecog ...

  5. 我的iOS开发系列博文

    之前目录性的总结了发表过的关于OC方面的文章,今天在目录性的总结一下有关iOS开发的文章.走过路过不要错过哦,今天的博文也全都是干货.写技术博客与大家交流一下思想也是不错的. 下面是我的技术博客中有关 ...

  6. iOS开发之微信聊天页面实现

    在上篇博客(iOS开发之微信聊天工具栏的封装)中对微信聊天页面下方的工具栏进行了封装,本篇博客中就使用之前封装的工具栏来进行聊天页面的编写.在聊天页面中主要用到了TableView的知识,还有如何在俩 ...

  7. iOS开发之微信聊天工具栏的封装

    之前山寨了一个新浪微博(iOS开发之山寨版新浪微博小结),这几天就山寨个微信吧.之前已经把微信的视图结构简单的拖了一下(IOS开发之微信山寨版),今天就开始给微信加上具体的实现功能,那么就先从微信的聊 ...

  8. 100个iOS开发/设计程序员面试题汇总,你将如何作答?

    100个iOS开发/设计程序员面试题汇总,你将如何作答? 雪姬 2015-01-25 19:10:49 工作职场 评论(0)   无论是对于公司还是开发者或设计师个人而言,面试都是一项耗时耗钱的项目, ...

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

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

随机推荐

  1. .Net Task<T>的一种比较神奇的卡死情况(Wait/Result卡死, await能得到结果)

    出现的环境.Net4.0 + WebApi1(4.0.30506.0) + Microsoft.Bcl.Async.1.0.168 自己死活看不出原因, 分享出来给大家看看,希望有人能找到问题的关键 ...

  2. asp.net页面后退,重复弹出上一页对话框处理办法

    我们在实例中,虽然页面内有导航,但是用户使用的时候难免会使用浏览器的后退按钮. 时常会发现,当后退的时候,上一页的对话框会自动弹出,下面是解决办法. 问题:使用此js代码,后退按钮时,重复显示对话框内 ...

  3. android释放内存的一个办法

    step 1:定义一个监听接口 public static interface OnLowMemoryListener { void onLowMemoryReceived(); } /* 何问起 h ...

  4. Object C中的数据类型表

    类型 例子 NSLog chars char 'a', '\n'  %c short int   — %hi, %hx, %ho unsigned short int   %hu, %hx, %ho ...

  5. sql查询重复记录和from子查询

    select name from (SELECT name,count(name) as countFROM Table WHERE (OrgUUId = (select top 1 uuid fro ...

  6. jquery基本选择器匹配多个元素

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 【Java每日一题】20161202

    20161201问题解析请点击今日问题下方的"[Java每日一题]20161202"查看 package Dec2016; public class Ques1202 { publ ...

  8. Mockups Mockplus 网页原型设计

    http://www.cocoachina.com/cms/wap.php?action=article&id=15319

  9. django pdb

    import pdb; pdb.set_trace()   http://charlee.li/debug-djangp-with-pdb.html https://github.com/tomchr ...

  10. C#Winform VScrollBar+Pannel自定义列表控件(原)

    该控件的主要实现思路是用的objective-c中的自定义控件思路,主视图中放子视图 效果图 (窗体调用代码) public partial class Form1 : RibbonForm { Li ...