iOS手势操作简介(六)
利用UIGestureRecognizer来对手势进行处理:
@interface HMViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imagView;
@end
@implementation HMViewController
(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.// pan
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];[_imagView addGestureRecognizer:pan];
}(void)pan:(UIPanGestureRecognizer *)pan
{
// 获取手指移动的位置
CGPoint trans = [pan translationInView:_imagView];_imagView.transform = CGAffineTransformTranslate(_imagView.transform, trans.x, trans.y);
// 复位
[pan setTranslation:CGPointZero inView:_imagView];
NSLog(@”%@”,NSStringFromCGPoint(trans));
}
warning pinch
- (void)addPinch
{
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
// 设置代理的原因:想要同时支持多个手势
pinch.delegate = self;
[_imagView addGestureRecognizer:pinch];
}
(void)pinch:(UIPinchGestureRecognizer *)pinch
{
_imagView.transform = CGAffineTransformScale(_imagView.transform, pinch.scale, pinch.scale);// 复位
pinch.scale = 1;
}
// Simultaneous:同时
// 默认是不支持多个手势
// 当你使用一个手势的时候就会调用
- (BOOL)gestureRecognizer:(UIGestureRecognizer )gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer )otherGestureRecognizer
{
return YES;
}
warning rotation
(void)addRotation
{
// rotation
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];
rotation.delegate = self;
[_imagView addGestureRecognizer:rotation];
}(void)rotation:(UIRotationGestureRecognizer *)rotation
{
NSLog(@”%f”,rotation.rotation);
// _imagView.transform = CGAffineTransformMakeRotation(rotation.rotation);
_imagView.transform = CGAffineTransformRotate(_imagView.transform, rotation.rotation);// 复位
rotation.rotation = 0;
}
warning Swipe
(void)addSwipe
{
// Swipe
// 一个手势只能识别一个方向
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[_imagView addGestureRecognizer:swipe];
}(void)swipe:(UISwipeGestureRecognizer *)swipe
{
NSLog(@”swipe”);
}
warning longPress
(void)addLongPress
{
// longPress
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];[_imagView addGestureRecognizer:longPress];
}(void)longPress:(UILongPressGestureRecognizer *)longPress
{
// 根据状态执行事件
if (longPress.state == UIGestureRecognizerStateBegan) {NSLog(@"longPress");
}
}
warning tap
(void)addTap
{
// tap
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
// 点按多少次才能触发手势
// tap.numberOfTapsRequired = 2;
//
// // 必须多少个手指触摸才能触发手势
// tap.numberOfTouchesRequired = 2;tap.delegate = self;
[_imagView addGestureRecognizer:tap];
}
// 这个触摸点能否触发手势
//- (BOOL)gestureRecognizer:(UIGestureRecognizer )gestureRecognizer shouldReceiveTouch:(UITouch )touch
//{
// CGPoint currentPoint = [touch locationInView:_imagView];
//
// if (currentPoint.x < _imagView.bounds.size.width * 0.5) {
// return NO;
// }else{
//
// return YES;
// }
//}
- (void)tap:(UITapGestureRecognizer *)tap
{
NSLog(@”tap”);
}
iOS手势操作简介(六)相关推荐
- iOS手势操作简介(一)
iOS中能够响应手势操作的类必须要继承自UIResponder,才能够处理手势响应操作. 默认继承了UIResponder的类有:UIApplication UIViewController UIVi ...
- iOS手势操作简介(五)
利用手势操作实现抽屉效果: 第一步:搭建UI (void)addChildView { // left UIView *leftView = [[UIView alloc] initWithFrame ...
- iOS手势操作简介(三)
监听触摸事件的做法 如果想监听一个view上面的触摸事件,之前的做法是 自定义一个view 实现view的touches方法,在方法内部实现具体处理代码 通过touches方法监听view触摸事件,有 ...
- iOS手势操作简介(四)
当事件传递到相应的UIResponder后,会首先调用: hitTest:withEvent: return (UIView *) UIApplication -> UIWindow 什么时候调 ...
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
http://www.cnblogs.com/huangjianwu/p/4675648.html 1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动 ...
- iOS 手势的使用 六个手势 轻拍 长按 拖拽 捏合 轻扫 旋转
手势识别在iOS上非常重要,手势操作移动设备的重要特征,极大的增加了移动设备使用便捷性. iOS系统在3.2以后,为方便开发这使用一些常用的手势,提供了UIGestureRecognizer类.手势识 ...
- iOS开发中手势处理简介(二)
iOS中手势操作事件的产生于传递 发生触摸事件后,系统会将该事件加入到一个由UIApplication管理的事件队列中 UIApplication会从事件队列中取出最前面的事件,并将事件分发下去以便处 ...
- iOS——6种系统手势操作
UIGestureRecognizer(手势识别器) 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了六种常用的手势(UIGestureRe ...
- iOS开发系列课程(08) --- 事件处理详解和手势操作
iOS中的事件分发 事件的分类 Touch Events(多点触摸事件) touchesBegan:withEvent:方法:一个或多个手指置于视图或窗口上 touchesMoved:withEven ...
最新文章
- loadrunner录制0事件_Android Studio 4.0发布:全新的 Motion 编辑器及众多更新
- opencv相机标定
- lucene DocValues——没有看懂
- jenkins配置小结
- laydate.render报错:日期格式不合法
- SQL Server商业智能功能–创建简单的OLAP多维数据集
- sparksql读取mysql表的两种方式
- Swagger2-注解说明
- 服装CAD计算机试衣的好处,浅议服装CAD三维试衣探究及创新.doc
- STM32F429之DCMI 数字相机接口
- 干眼能从事计算机工作吗,上班族长时间面对电脑须谨慎干眼症
- web-页面body添加背景图片
- Enterprise Architect 15 使用指南 II
- 荣耀MagicOS 7.0正式发布;快手科技2022年第三季度收入同比增长12.9% | 美通企业日报...
- Vue2:使用Vant UI实现网易云评论页上拉和下拉刷新
- mac搜索不到wifi wtg_Mac连不上WiFi怎么办?Mac连不上无线网络解决办法
- 【AD小知识】PCB布线理论及实际操作
- 内存不能为读的解决办法
- Faster RCNN训练FLIR红外线数据集
- Window 任务栏里面Idea图标出现空白
热门文章
- mysql key uni_uni app 踩坑实录
- [蓝桥杯][2019年第十届真题]修改数组(并查集)
- 食物链 POJ - 1182(带权并查集模板)
- 和为K的组合(01背包)
- html 星空效果,使用css实现星空效果!
- ROS2学习(九).ROS概念 - ROS 2参数(ROS 2 parameters)
- android 模拟来电广播,在Android模拟器上模拟来电
- 13计算机组装,计算机组装与维修—教案13 .pdf
- 网页中加载obj模型比较慢_R语言估计时变VAR模型时间序列的实证研究分析案例...
- CodeForces - 1102A(思维题)