首页 / IOS / ios开发之手势处理 之手势识别一
ios开发之手势处理 之手势识别一
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ios开发之手势处理 之手势识别一,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2299字,纯文字阅读大概需要4分钟。
内容图文
#import " ViewController.h " @interface ViewController ()<UIGestureRecognizerDelegate> @property (weak, nonatomic) IBOutlet UIImageView *imageV; @end@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //1.创建手势 UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; //设置轻扫的方向(一个轻扫手势只能对应一个方向) swipe.direction = UISwipeGestureRecognizerDirectionLeft; UISwipeGestureRecognizer *swipe1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; //设置轻扫的方向(一个轻扫手势只能对应一个方向) swipe1.direction = UISwipeGestureRecognizerDirectionRight; //2.添加手势 [self.imageV addGestureRecognizer:swipe]; [self.imageV addGestureRecognizer:swipe1]; } //当轻扫时调用 - (void)swipe:(UISwipeGestureRecognizer *)swipe{ if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) { NSLog(@"left"); }elseif(swipe.direction == UISwipeGestureRecognizerDirectionRight){ NSLog(@"right"); } //NSLog(@"%s",__func__);} //长按手势 - (void)longP{ //1.创建手势 UILongPressGestureRecognizer *longP = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longP:)]; //2.添加手势 [self.imageV addGestureRecognizer:longP]; } //当长按时调用(当长按移动时,该方法会持续调用) - (void)longP:(UILongPressGestureRecognizer *)longP{ NSLog(@"%s",__func__); //判断手势的状态if (longP.state == UIGestureRecognizerStateBegan) { NSLog(@"开始长按"); }elseif(longP.state == UIGestureRecognizerStateChanged){ NSLog(@"长按时移动"); }elseif(longP.state == UIGestureRecognizerStateEnded){ NSLog(@"手指离开"); } } //点按手势 - (void)setUpTap{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]; tap.delegate = self; //2.添加手势 [self.imageV addGestureRecognizer:tap]; } //3.实现手势方法 - (void)tap{ NSLog(@"%s",__func__); } //是否允许接收手指. //-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { //让当前的图片,左边不能点击 ,右边能够点击 //获取当前手指的点 // CGPoint curP = [touch locationInView:self.imageV]; //// if (curP.x > self.imageV.frame.size.width * 0.5) { ////在右边 // return YES; // }else{ ////在左边 // return NO; // } //////} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.} @end
原文:http://www.cnblogs.com/cqb-learner/p/5815954.html
内容总结
以上是互联网集市为您收集整理的ios开发之手势处理 之手势识别一全部内容,希望文章能够帮你解决ios开发之手势处理 之手势识别一所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。