简单方法实现 uitableviewcell 左滑出现各种自定义功能视图
2014-08-09 11:27
731 查看
一 先继承 tableviewcell
二添加左滑右滑
UISwipeGestureRecognizer *swipeLeft=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeCell:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeCell:)];
swipeRight.direction=UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:swipeRight];
三 实现左滑右滑功能
if (swipe.direction==UISwipeGestureRecognizerDirectionLeft) {
__block CGPoint point=self.contentView.center;
if (point.x>=(self.frame.size.width-self.swiftLeftLength)) {
[self stepLeftView];
[UIView animateWithDuration:0.15 animations:^{
point.x=point.x-self.swiftLeftLength;
self.contentView.center=point;
UIView *leftView=[self viewWithTag:505];
CGRect frame=leftView.frame;
frame.origin.x=self.frame.size.width-self.swiftLeftLength;
leftView.frame=frame;
} completion:^(BOOL finished) {
}];
}
}else if (swipe.direction==UISwipeGestureRecognizerDirectionRight){
__block CGPoint point=self.contentView.center;
if (point.x<(self.frame.size.width-self.swiftLeftLength)) {
[UIView animateWithDuration:0.15 animations:^{
point.x=point.x+self.swiftLeftLength;
self.contentView.center=point;
UIView *leftView=[self viewWithTag:505];
CGRect frame=leftView.frame;
frame.origin.x=self.frame.size.width;
leftView.frame=frame;
} completion:^(BOOL finished) {
[self removeLeftView];
}];
}
}
四添加左滑出来的视图
-(void)stepLeftView{
UIView *leftView=[[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width, 0, self.swiftLeftLength, self.frame.size.height)];
leftView.tag=505;
[leftView addSubview:self.leftContentView];
[self addSubview:leftView];
}
五 解决cell重用机制导致的问题
- (void)prepareForReuse {
[super prepareForReuse];
[self reset];
}
demo 下载 http://download.csdn.net/detail/wjszf/7733277
二添加左滑右滑
UISwipeGestureRecognizer *swipeLeft=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeCell:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeCell:)];
swipeRight.direction=UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:swipeRight];
三 实现左滑右滑功能
if (swipe.direction==UISwipeGestureRecognizerDirectionLeft) {
__block CGPoint point=self.contentView.center;
if (point.x>=(self.frame.size.width-self.swiftLeftLength)) {
[self stepLeftView];
[UIView animateWithDuration:0.15 animations:^{
point.x=point.x-self.swiftLeftLength;
self.contentView.center=point;
UIView *leftView=[self viewWithTag:505];
CGRect frame=leftView.frame;
frame.origin.x=self.frame.size.width-self.swiftLeftLength;
leftView.frame=frame;
} completion:^(BOOL finished) {
}];
}
}else if (swipe.direction==UISwipeGestureRecognizerDirectionRight){
__block CGPoint point=self.contentView.center;
if (point.x<(self.frame.size.width-self.swiftLeftLength)) {
[UIView animateWithDuration:0.15 animations:^{
point.x=point.x+self.swiftLeftLength;
self.contentView.center=point;
UIView *leftView=[self viewWithTag:505];
CGRect frame=leftView.frame;
frame.origin.x=self.frame.size.width;
leftView.frame=frame;
} completion:^(BOOL finished) {
[self removeLeftView];
}];
}
}
四添加左滑出来的视图
-(void)stepLeftView{
UIView *leftView=[[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width, 0, self.swiftLeftLength, self.frame.size.height)];
leftView.tag=505;
[leftView addSubview:self.leftContentView];
[self addSubview:leftView];
}
五 解决cell重用机制导致的问题
- (void)prepareForReuse {
[super prepareForReuse];
[self reset];
}
demo 下载 http://download.csdn.net/detail/wjszf/7733277
相关文章推荐
- 基于百度地图 Android SDKv1.3.5实现简单的定位功能,自定义标题栏
- 自定义Oracle 函数,传入参数,实现简单的功能
- JavaScript自定义方法实现trim()、Ltrim()、Rtrim()的功能
- 自定义一个view,并实现最简单的手势识别功能(上)
- 一种简单方法实现页面导出(Excel)功能
- 自定义安装 Python 后,出现方向键无法用,按下方向键后,终端显示的式相应的字符编码,而不是方向键的功能的解决方法
- 使用Java实现简单的server/client回显功能的方法介绍
- JavaScript自定义方法实现trim()、Ltrim()、Rtrim()的功能
- 超简单的自定义标签封装实现的JSP分页显示功能
- RMI(远程方法调用)实现简单的查单词功能
- 地址方法[ios开发]利用有道翻译API实现简单的翻译功能地址方法
- 实现视频长时间播放而显示器不会关闭或者屏保出现的简单方法
- rcp(插件开发)CNF 自定义视图-右键菜单-的简单实现
- [C#]简单重写IComparer接口,实现自己的String.CompareTo 方法,自定义比较规则。
- Java编程构建简单画图板3——构建自定义队列实现重绘功能
- 基于百度地图 Android SDKv1.3.5实现简单的定位功能,自定义标题栏
- CSS相册简单实现方法(功能分析及代码)
- 自定义一个view,并实现最简单的手势识别功能(下)
- 利用特性给方法实现自定义的功能
- 【IOS功能实现】之 获取各种文件的目录路径的方法