IOS添加滑动手势
来源:互联网 发布:sublime的js插件 编辑:程序博客网 时间:2024/05/15 14:52
添加滑动手势有两种方法
方法一:
方法二:
添加可以区分方向的手势 特定滑动方向时 才会调用相应的操作
方法一:
添加手势不分方向, 左 右 上 下滑动都会调用方法
UIPanGestureRecognizer *removeSelfView = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(removeSelfView:)]; [self addGestureRecognizer:removeSelfView];
- (void)removeSelfView:(UIPanGestureRecognizer *)gesture{ NSLog(@"滑动方法调用了"); [self removeFromSuperview];}
方法二:
添加可以区分方向的手势 特定滑动方向时 才会调用相应的操作
UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipes:)]; left.direction=UISwipeGestureRecognizerDirectionLeft; [self addGestureRecognizer:left]; UISwipeGestureRecognizer *right = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipes:)]; right.direction=UISwipeGestureRecognizerDirectionRight; [self addGestureRecognizer:right]; UISwipeGestureRecognizer *up = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipes:)]; up.direction=UISwipeGestureRecognizerDirectionUp; [self addGestureRecognizer:up]; UISwipeGestureRecognizer *down = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipes:)]; down.direction=UISwipeGestureRecognizerDirectionLeft; [self addGestureRecognizer:down];
-(void)handleSwipes:(UISwipeGestureRecognizer *)recognizer{ if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft){ NSLog(@"向左边滑动了!!!!!!"); } if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) { NSLog(@"向右边滑动了!!!!!!"); } if (recognizer.direction == UISwipeGestureRecognizerDirectionUp) { NSLog(@"向上边滑动了!!!!!!"); } if (recognizer.direction == UISwipeGestureRecognizerDirectionDown) { NSLog(@"向下边滑动了!!!!!!"); }}
使用手势很简单,分为三步:
1 创建手势识别器对象实例。创建时,指定一个回调方法,当手势开始,改变、或结束时,执行回调方法。
2 设置手势识别器对象实例的相关属性(可选部分)
3 添加到需要识别的 View 中。每个手势只对应一个 View,当屏幕触摸在 View 的边界内时,如果手势和预定的一样,那就会执行回调方法。
PS:一个手势只能对应一个 View,但是一个 View 可以有多个手势。建议在真机上测试这些手势,模拟器操作不太方便,可能导致认为手势失效的情况。(模拟器测试捏合和旋转手势时,按住 option 键,再用触摸板或鼠标操作)
1 0
- ios添加滑动手势
- IOS-滑动手势添加
- IOS添加滑动手势
- xamarin.iOS 滑动视图上添加边缘滑动手势
- UIWebView 添加滑动手势
- iOS 上下左右滑动手势
- ios 左右滑动手势
- iOS 禁止滑动手势
- iOS手势滑动返回
- iOS禁用手势滑动
- iOS 上下左右滑动手势
- tableview添加上下滑动手势
- 添加手势,滑动切换网页
- iOS手势之 响应上下左右滑动手势
- ios 上下左右滑动手势
- [ios] 响应上下左右滑动手势
- iOS上下左右-滑动手势
- ios--响应上下左右滑动手势
- 设置布局默认为LinearLayout,却成了RelativeLayout
- IOS retain,copy,assign理解 区别 使用
- 欢迎使用CSDN-markdown编辑器
- hdu5025
- 高效的SQLSERVER分页查询(多种方案)
- IOS添加滑动手势
- 税率
- 大规模运行MongoDB应该知道的10件事
- hive 增加自定义udf
- java synchronized死锁的好例子
- KMP算法——Knuth–Morris–Pratt algorithm
- js+html实现遮罩层效果
- jsapi 调用创建企业会话和企业通讯录
- C语言存储类型