六种手势如下:

UITapGestureRecognizer

[UIPinchGestureRecognizer](捏合)

[UIRotationGestureRecognizer](旋转)

([UISwipeGestureRecognizer]滑动,快速移动)

[UIPanGestureRecognizer](平移,慢速移动)

[UILongPressGestureRecognizer](长按)

以上六种只是常用的一些手势,在这里作此简述

创建图片对象

// 创建图片对象

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];

// 设置图片内容

imageView.image = [UIImage imageNamed:@“自己图片名”];

// 设置图片居中

imageView.center = self.view.center;

// 设置用户交互

imageView.userInteractionEnabled = YES;

// 添加到视图上

[self.view addSubview:imageView];
UITapGestureRecognizer (点击手势)

//1.创建手势对象

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];

//2.手势相关的属性

//点击次数(默认1)

tapGesture.numberOfTapsRequired = 1;

//手指的个数(默认1)

tapGesture.numberOfTouchesRequired = 1;

//3.把手势与视图相关联

[imageView addGestureRecognizer:tapGesture];
// 点击事件

-(void)tapClick:(UITapGestureRecognizer *)tap{

NSLog(@“点击图片了”);

}
UIPinchGestureRecognizer (捏合手势)

//捏合手势

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pichClick:)];

[imageView addGestureRecognizer:pinchGesture];

// 捏合事件

-(void)pichClick:(UIPinchGestureRecognizer *)pinch{

//缩放的系数

NSLog(@"%.2lf",pinch.scale);

//固定写法

pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);

//重置缩放系数(否则系数会累加)

pinch.scale = 1.0;

}
UIRotationGestureRecognizer (旋转手势)

//旋转手势

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationClick:)];

[imageView addGestureRecognizer:rotationGesture];

-(void)rotationClick:(UIRotationGestureRecognizer *)rotation{

NSLog(@“qqq”);

}
UISwipeGestureRecognizer (滑动手势)

// 滑动手势

UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeClick:)];

// 设置轻扫的方向

leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;

[self.view addGestureRecognizer:leftSwipe];

UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeClick:)];

// 右扫

rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;

[self.view addGestureRecognizer:rightSwipe];

// 滑动事件

-(void)swipeClick:(UISwipeGestureRecognizer *)swpie{

// 如果是左扫

if (swpie.direction == UISwipeGestureRecognizerDirectionLeft ) {

NSLog(@“左扫!”);

}else{

NSLog(@“右扫!”);

}
}

UIPanGestureRecognizer (平移手势)

//平移手势

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panClick:)];

[imageView addGestureRecognizer:panGesture];

// 平移事件

-(void)panClick:(UIPanGestureRecognizer *)pan{

NSLog(@“响应了。。。”);

//通过pan手势,能够获取到pan.view在self.view上的偏移量

CGPoint point = [pan translationInView:self.view];

NSLog(@“x=%.2lf y=%.2lf”,point.x,point.y);

//改变中心点坐标(原来的中心点+偏移量=当前的中心点)

CGPoint newCenter = CGPointMake(pan.view.center.x + point.x, pan.view.center.y + point.y);

// CGPointZero<==>CGPointMake(0,0)

//限制拖动范围

newCenter.y = MAX(pan.view.frame.size.height/2, newCenter.y);

newCenter.y = MIN(self.view.frame.size.height - pan.view.frame.size.height/2, newCenter.y);

newCenter.x = MAX(pan.view.frame.size.width/2, newCenter.x);

newCenter.x = MIN(self.view.frame.size.width - pan.view.frame.size.width/2, newCenter.x);

pan.view.center = newCenter;

//每次调用之后,需要重置手势的偏移量,否则偏移量会自动累加

[pan setTranslation:CGPointZero inView:self.view];

}
UILongPressGestureRecognizer (长按手势)

//长按手势

UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];

//用几个手指触屏,默认1

longPressGesture.numberOfTouchesRequired = 1;

//设置最短长按时间,单位为秒(默认0.5)

longPressGesture.minimumPressDuration = 1;

//设置手势识别期间所允许的手势可移动范围

longPressGesture.allowableMovement = 10;

[imageView addGestureRecognizer:longPressGesture];

// 长按事件

-(void)longPressClick:(UILongPressGestureRecognizer *)press{

//state属性是所有手势父类提供的方法,用于记录手势的状态

if(press.state == UIGestureRecognizerStateBegan){

NSLog(@“长按手势开始响应!”);

}else if (press.state == UIGestureRecognizerStateChanged){

NSLog(@“长按手势状态发生改变!”);

}else{

NSLog(@“长按手势结束!”);

}
}

iOS 常见的六种 手势相关推荐

  1. IOS开发基础之手势解锁项目案例

    IOS开发基础之手势解锁项目案例 项目最终实现效果. 由于缺少红色的error背景图.我自己从安卓项目找到一个手势解锁,然后通过ps添加粉红色的红圈,才得以解决.为了分享给大家源码,github和本地 ...

  2. iOS常见错误8-Missing iOS Distribution signing identity for “XXXXX”. Xcode can request one for you.

    iOS常见错误8-Missing iOS Distribution signing identity for "XXXXX". Xcode can request one for ...

  3. iOS常见的设计模式:工厂设计模式

    iOS常见的设计模式:工厂设计模式 简单工厂模式: 简单工厂模式(Simple Factory Pattern):专门定义一个类(工厂类)来负责创建其他类的实例.可以根据创建方法的参数来返回不同类的实 ...

  4. iOS多点触摸与手势

    转自: http://book.51cto.com/art/201110/297453.htm 4.2.2 iOS多点触摸与手势 iOS赋予用户至少3.5英寸的宽广视野,在当时可谓令人眼前一亮.在这不 ...

  5. 蛋花花总结互联网营销最为常见的六种模式

    蛋花花总结互联网营销最为常见的六种模式!如今随着互联网的普及互联网营销也非常的火,我们在很多地方都能见到相关广告.蛋花花总结了一下发现在互联网营销方面有最为常见的六种模式,下面就来介绍一下. 蛋花花总 ...

  6. 常见的六种web攻击

    常见的六种web攻击 一.XSS XSS(跨脚本攻击):指通过存在安全漏洞的Web网站注册用户的浏览器内运行非法的HTML标签或JavaScript进行的一种攻击,即恶意攻击者往 Web 页面里插入恶 ...

  7. 机器学习中常见的六种分类算法(附Python源码+数据集)

    今天和大家学习一下机器学习中常见的六种分类算法,如K近邻.决策树.朴素贝叶斯.逻辑回归.支持向量机.随机森林 除了介绍这六种不同分类算法外,还附上对应的Python代码案例,并分析各自的优缺点. 01 ...

  8. 【转】iOS右滑返回手势全解和最佳实施方案

    序言 在ios7以后,苹果推出了手势滑动返回功能,也就是从屏幕左侧向右滑动可返回上一个界面.大大提高了APP在大屏手机和iPad上的操作体验,场景切换更加流畅.做右滑返回手势配置时,可能会遇到的 问题 ...

  9. iOS——6种系统手势操作

    UIGestureRecognizer(手势识别器) 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了六种常用的手势(UIGestureRe ...

  10. ios 常见性能优化

    1. 用ARC管理内存 2. 在正确的地方使用reuseIdentifier 3. 尽可能使Views透明 4. 避免庞大的XIB 5. 不要block主线程 6. 在Image Views中调整图片 ...

最新文章

  1. 收藏 | 服务器和存储技术知识
  2. mysql using filesort_Mysql执行计划中的Using filesort
  3. JVM之XX参数详解
  4. cocos js 3.8.1 clippingNode 不能被 ccui.ScrollView 或者ccui.Layout裁剪的bug
  5. 由于没有远程桌面授权服务器可以提供许可证,远程会话被中断。
  6. c语言口袋妖怪代码大全,口袋妖怪代码大全.docx
  7. KVM虚拟化技术浅析
  8. 2022前端HTML5面试题
  9. vyos v1.2安装flask
  10. ARM与x86之1--Wintel帝国
  11. 结对编程四则运算第三周-挑战出题(20172301、20172304、20172328)
  12. vxlan报文 wireshark_VXLAN原理_ISIS、BGP、MPLS v隧道、QOS 技术精讲(肖哥)_华为认证视频-51CTO学院...
  13. 发布infopath模板到sharepoint站点(Infopath 2007)
  14. 系统安装教程之硬盘分区格式化(MBR或GPT)
  15. 前端本地静态模板下载功能
  16. 规划云:GIS相关模块
  17. Kindle已连接WiFi网络,但无法连接互联网的解决办法
  18. 什么是BI、数据仓库、数据湖和数据中台,他们有什么差异?
  19. 页面分享到微博、qq、qqzone
  20. YYKit Demo

热门文章

  1. 诺基亚称霸时代终结 Ovi商店面临命运抉择
  2. C语言—贪吃蛇双人对战
  3. windows 进程之csrss.ext
  4. 使用 .NET HttpClient 下载 PDF 文件的DEMO
  5. Ubuntu常用软件安装
  6. 前大疆RoboMaster技术总监:机器人工程师学习计划
  7. displayTag
  8. 小技巧:Win7屏保变梦幻桌面
  9. CAD 卸载工具,完美彻底卸载清除干净cad各种残留注册表和文件
  10. 网络流(最大流)基础入门