iOS开发-UISwipeGestureRecognizer滑动手势
滑动手势也算是iOS中交互中很重要的一部分,上下左右滑动,UISwipeGestureRecognizer可以很轻松的解决这个问题,没什么难度直接看代码吧:
UISwipeGestureRecognizer *upSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)]; upSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionUp; [self.view addGestureRecognizer:upSwipeGestureRecognizer]; UISwipeGestureRecognizer *downSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)]; downSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionDown; [self.view addGestureRecognizer:downSwipeGestureRecognizer]; UISwipeGestureRecognizer *leftSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)]; leftSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:leftSwipeGestureRecognizer]; UISwipeGestureRecognizer *rightSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)]; rightSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:rightSwipeGestureRecognizer];
手势处理:
-(void)swipeGestureRecognizer:(UISwipeGestureRecognizer *)recongnizer{ if (recongnizer.direction==UISwipeGestureRecognizerDirectionUp) { NSLog(@"向上滑动"); NSLog(@"博客园-FlyElephant"); } if (recongnizer.direction==UISwipeGestureRecognizerDirectionDown) { NSLog(@"向下滑动"); NSLog(@"原文地址:http://www.cnblogs.com/xiaofeixiang"); } if (recongnizer.direction==UISwipeGestureRecognizerDirectionLeft) { NSLog(@"向左滑动"); NSLog(@"iOS技术交流群:228407086"); } if (recongnizer.direction==UISwipeGestureRecognizerDirectionRight) { NSLog(@"向右滑动"); } }
效果图:
作者:FlyElephant
出处:http://www.cnblogs.com/xiaofeixiang
说明:博客经个人辛苦努力所得,如有转载会特别申明,博客不求技惊四座,但求与有缘人分享个人学习知识,生活学习提高之用,博客所有权归本人和博客园所有,如有转载请在显著位置给出博文链接和作者姓名,否则本人将付诸法律。
出处:http://www.cnblogs.com/xiaofeixiang
说明:博客经个人辛苦努力所得,如有转载会特别申明,博客不求技惊四座,但求与有缘人分享个人学习知识,生活学习提高之用,博客所有权归本人和博客园所有,如有转载请在显著位置给出博文链接和作者姓名,否则本人将付诸法律。