IOS 学习---触摸事件与手势
2019独角兽企业重金招聘Python工程师标准>>>
单击手势与双击手势
//单击手势UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction:)];//设置点击的次数tap1.numberOfTapsRequired = 1;//设置手指的个数tap1.numberOfTouchesRequired = 1;//将手势添加到视图上[self.view addGestureRecognizer:tap1];//双击手势UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleAction:)];tap2.numberOfTapsRequired = 2;//添加手势[self.view addGestureRecognizer:tap2];//区别两个手势[tap1 requireGestureRecognizerToFail:tap2];
}//单击手势响应的事件
- (void)singleTapAction:(UITapGestureRecognizer *)tap {//关闭手势
// tap.enabled = NO;//获取手势所在的视图UIView *view = tap.view;view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(10)/10.0 green:arc4random_uniform(10)/10.0 blue:arc4random_uniform(10)/10.0 alpha:1];NSLog(@"singleTapAction");
}//双击手势响应的事件
- (void)doubleAction:(UITapGestureRecognizer *)tap {NSLog(@"doubleAction");
}
轻扫手势
- (void)_initSwipeGesture {UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];//设置轻扫的方向/*UISwipeGestureRecognizerDirectionRightUISwipeGestureRecognizerDirectionLeftUISwipeGestureRecognizerDirectionUpUISwipeGestureRecognizerDirectionDown*/swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;[self.view addGestureRecognizer:swipeGesture];
}- (void)swipeAction:(UISwipeGestureRecognizer *)swipe {NSLog(@"swipeAction");
}
平移手势
- (void)_initPanGesture {UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];[self.view addGestureRecognizer:panGesture];
}- (void)panAction:(UIPanGestureRecognizer *)pan {//手指所在的坐标CGPoint point = [pan locationInView:self.view];_view.center = point;
}
长按手势
- (void)_initLongGesture {UILongPressGestureRecognizer *pressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pressAction:)];//设置最短时间pressGesture.minimumPressDuration = 1;[self.view addGestureRecognizer:pressGesture];}- (void)pressAction:(UILongPressGestureRecognizer *)press {/*UIGestureRecognizerStateBegan 开始UIGestureRecognizerStateChanged 改变UIGestureRecognizerStateEnded 结束UIGestureRecognizerStateCancelled 取消*/if (press.state == UIGestureRecognizerStateBegan) {NSLog(@"pressAction");}
}
旋转手势
- (void)_initRotationGesture {UIImageView *imgView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];imgView.userInteractionEnabled = YES;imgView.image = [UIImage imageNamed:@"5.jpeg"];[self.view addSubview:imgView];UIRotationGestureRecognizer *rotationGresutre = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];[imgView addGestureRecognizer:rotationGresutre];
}- (void)rotationAction:(UIRotationGestureRecognizer *)rotationGesture {NSLog(@"%f",rotationGesture.rotation);UIImageView *imgView = (UIImageView *)rotationGesture.view;if (rotationGesture.state == UIGestureRecognizerStateChanged) {imgView.transform = CGAffineTransformMakeRotation(rotationGesture.rotation);}else if (rotationGesture.state == UIGestureRecognizerStateEnded || rotationGesture.state == UIGestureRecognizerStateCancelled) {[UIView animateWithDuration:0.3 animations:^{imgView.transform = CGAffineTransformIdentity;}];}}
缩放手势
- (void)_initPinchGesture {UIImageView *imgView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];imgView.userInteractionEnabled = YES;imgView.image = [UIImage imageNamed:@"5.jpeg"];[self.view addSubview:imgView];UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];[imgView addGestureRecognizer:pinchGesture];}- (void)pinchAction:(UIPinchGestureRecognizer *)pinch {// pinch.scale; //缩放比NSLog(@"pinchAction:%f",pinch.scale);UIImageView *imgView = (UIImageView *)pinch.view;if (pinch.state == UIGestureRecognizerStateChanged) {imgView.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);}else if (pinch.state == UIGestureRecognizerStateEnded || pinch.state == UIGestureRecognizerStateCancelled) {[UIView animateWithDuration:0.3 animations:^{imgView.transform = CGAffineTransformIdentity;}];}}
转载于:https://my.oschina.net/zhangqy/blog/505511
IOS 学习---触摸事件与手势相关推荐
- iOS 一一 触摸事件和手势
iOS触摸事件和手势 文章出处:http://www.jianshu.com/p/cb0314b72883 在iOS中,触摸表示用户手指触击屏幕及在屏幕上移动时,系统不断发送给应用程序对象,一个UIT ...
- iOS:触摸事件、手势识别、摇晃事件、耳机线控
概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事件(手势操作).运动事件. ...
- IOS中触摸事件学习
IOS中触摸事件学习 1. 事件的声明周期 2. 系统相应阶段 3. APP响应阶段 4. 触摸.事件.响应者 4.1 UITouch(触摸) 4.2 UIEvent(事件真身) 4.3 UIResp ...
- ios事件-触摸事件2(手势 和 pointInSide()、hitTest()、touchesBegan()、touchesMoved()、touchesEnded()的关系)
ios事件-触摸事件2(手势 和 pointInSide().hitTest().touchesBegan().touchesMoved().touchesEnded().touchesCancell ...
- JS—触摸事件、手势事件
JS-触摸事件.手势事件 dbclick 触屏设备不支持双击事件.双击浏览器窗口,会放大画面. 可以通过在head标签内加上这么一行: <meta name="viewport&quo ...
- iOS UITouch触摸与UIGesture手势.01.事件、触摸(touch)事件
一.iOS事件: 1.事件:事件就是当你在手机上点击手机屏幕.滑动手机翻面.摇动手机的时候,手机做出一些反应,对应的在应用程序里实现了某些代码的某些功能,完成这个过程就是一个事件. 2.iOS事件类型 ...
- iOS学习9_事件分发amp;响应链
iOS的三种事件:触摸事件/运动事件/远程控制事件 typedef enum { UIEventTypeTouches, UIEventTypeMotion, UIEventTypeRemoteCon ...
- 触摸事件练习 -- 手势解锁
Main.storyboard <?xml version="1.0" encoding="UTF-8" standalone="no" ...
- iOS开发触摸事件的传递
1. iOS中的三种事件类型 触摸事件.加速计事件.远程事件. 触摸事件:通过触摸.手势进行触发(例如手指点击.缩放) 加速计事件:通过加速器进行触发(例如手机晃动,典型应用是微信摇一摇) 远程事件: ...
- iOS中触摸事件传递和响应原理
系统响应阶段 1.手指触碰屏幕,屏幕感受到触摸后,将事件交由IOKit来处理. 2.IOKIT将触摸事件封装成IOHIDEvent对象,并通过mach port传递给SpringBoard进程. ma ...
最新文章
- ajax按钮改变数据状态
- php组合设计模式(composite pattern)
- ubuntu开启端口_RChain节点运行无门槛教程(二)--Windows-Ubuntu
- 重要的基础注解@import
- Git迁移 从SVN到Git
- JNI开发笔记(八)--Java读取txt文件进行JNI测试
- 微信小程序独家秘笈之左滑删除
- oppoJava面试!mysql客户端安装包
- 教育计算机缩写,{教育管理}计算机缩写术语完全介绍宝典.docx
- 贪心 - [POI2006]ORK-Ploughing
- 金陵科技学院c语言实验报告册,C语言实验报告册a
- 社交巨人屏蔽Google搜索 Facebook发展强劲拟上市
- docker容器必须要有前台进程
- java中负数_Java中负数以及类型转换问题
- 基于AD9854信号发生电路和MSK调制信号
- 25. Green Living 绿色生活
- proxmox ve 中文社区_基于ProXmoX VE的虚拟化家庭服务器(篇一)—ProXmoX VE 安装及基础配置...
- 京东app优惠券python抓取_如何使用fiddler抓取京东app的领券链接
- 文件7:文件路径基础
- 北理工计算机系裴教授,裴明涛_北京理工大学计算机学院
热门文章
- MIT科学家Dimitri P. Bertsekas最新2019出版《强化学习与最优控制》(附书稿PDF讲义)...
- 杨立昆辞Facebook人工智能实验室主任,任首席科学家
- 谷歌开源 TFGAN,让训练和评估 GAN 变得更加简单
- “技术崇拜”与“技术恐惧”都会阻碍 AI 创新,“技术节制”才是正道
- 49 岁的红杉资本遭遇黑客攻击
- TIOBE 12 月编程语言:Python 有望第四次成为年度语言!
- 大厂技术资料:Redis+Nginx+Spring全家桶+Dubbo精选
- FlashFXP客户端 FTP连接,连接很慢的情况,
- log4j的日志级别(ssm中log4j的配置)
- 临时表空间过大解决方法