手势学习
2015-06-29 15:21
447 查看
// // GestureViewController.m // AppUI组件学习 // // Created by 麦子 on 15/6/29. // Copyright (c) 2015年 麦子. All rights reserved. // #import "GestureViewController.h" @interface GestureViewController () @end @implementation GestureViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"手势识别"; self.view.backgroundColor = [UIColor whiteColor]; // 识别手势类 [self testPan]; } // 点击类测试 - (void)testTap{ // 点击 UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(grEvent:)]; gr.numberOfTapsRequired = 1; [self.view addGestureRecognizer:gr]; UITapGestureRecognizer *gr2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dbGrEvent:)]; gr2.numberOfTapsRequired = 2; [self.view addGestureRecognizer:gr2]; // 当单击失败的时候,才双机 [gr requireGestureRecognizerToFail:gr2];// 区分单机和双击问题。 } // 滑动 - (void)testSwipe{ UISwipeGestureRecognizer *sw = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swEvent:)]; [sw setDirection:UISwipeGestureRecognizerDirectionLeft];//分别4个方向 [self.view addGestureRecognizer:sw]; } // 长按 - (void)testLogTap{ UILongPressGestureRecognizer *longPr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)]; longPr.minimumPressDuration = 3;// 最小3秒时间 [self.view addGestureRecognizer:longPr]; } // 捏合 放大缩小 - (void)testPin{ UIPinchGestureRecognizer *pin = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinEvent:)]; [self.view addGestureRecognizer:pin]; } // 旋转 - (void)testRota{ UIRotationGestureRecognizer *rota = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotaEvent:)]; [self.view addGestureRecognizer:rota]; } // 拖拽 - (void)testPan{ UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panEvent:)]; [self.view addGestureRecognizer:pan]; } // 拖拽 - (void)panEvent:(UIPanGestureRecognizer *)sender{ // 这一点到前面一点的移动的距离 CGPoint point = [sender translationInView:self.view]; // 调整视图的中心位置 sender.view.center = CGPointMake(sender.view.center.x+point.x, sender.view.center.y+point.y); // 恢复位置 [sender setTranslation:CGPointZero inView:self.view]; } // 这个是两个之间的距离 - (void)rotaEvent:(UIRotationGestureRecognizer *)obj{ NSLog(@"旋转。。。。%g度",obj.rotation*180/M_PI); // 相对上一次的增量。 } // 这个是两个之间的距离 - (void)pinEvent:(UIPinchGestureRecognizer *)obj{ NSLog(@"捏合。。。。%f",obj.scale); } // 长按监听---长按会进来方法两次,所以要通过状态来进行区别 - (void)longTap:(UILongPressGestureRecognizer *)longTapEvent{ NSLog(@"3秒显示一次,抬起的时候,显示一次。"); if (longTapEvent.state == UIGestureRecognizerStateBegan) { NSLog(@"时间到,触发吧"); }else if(longTapEvent.state == UIGestureRecognizerStateEnded){ NSLog(@"时间到,消失吧"); } } - (void)swEvent:(id)obj{ NSLog(@"滑动监听。。。。。"); } - (void)grEvent:(id)obj{ NSLog(@"单击了。。。。。"); } - (void)dbGrEvent:(id)obj{ NSLog(@"双击了。。。。"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //// 触摸开始 //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // // // 位置 // UITouch *touch = [touches anyObject]; // long count = [touch tapCount]; // 点击的个数 // // // NSLog(@"触摸开始----手指个数-%ld-----点击个数%ld",touches.count,count); // //} //// 触摸结束 //- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ // // NSLog(@"触摸结束----%ld",touches.count); // 手指个数 // // //} // //// 移动 //- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ // UITouch *touch = [touches anyObject]; // CGPoint point = [touch locationInView:self.view]; // // NSLog(@"触摸移动----%ld",touches.count); // NSLog(@"触摸移动--X:--%f----Y:--%f",point.x,point.y); //} // //// 触摸事件取消 //- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ // // NSLog(@"触摸取消"); // //} @end
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍
- 基于Android中手势交互的实现方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- iOS开发之路--微博OAuth授权_取得用户授权的accessToken
- ios通过按钮点击异步加载图片
- ios中图像进行压缩方法汇总