IOS uitableviewcell 左滑 自定义
一 先继承 tableviewcell
二添加左滑右滑
UISwipeGestureRecognizer*swipeLeft=[[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swipeCell:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
[selfaddGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer*swipeRight=[[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swipeCell:)];
swipeRight.direction=UISwipeGestureRecognizerDirectionRight;
[selfaddGestureRecognizer:swipeRight];
三 实现左滑右滑功能
if(swipe.direction==UISwipeGestureRecognizerDirectionLeft) {
__blockCGPointpoint=self.contentView.center;
if(point.x>=(self.frame.size.width-self.swiftLeftLength)) {
[selfstepLeftView];
[UIViewanimateWithDuration:0.15animations:^{
point.x=point.x-self.swiftLeftLength;
self.contentView.center=point;
UIView*leftView=[selfviewWithTag:505];
CGRectframe=leftView.frame;
frame.origin.x=self.frame.size.width-self.swiftLeftLength;
leftView.frame=frame;
}completion:^(BOOLfinished) {
}];
}
}elseif(swipe.direction==UISwipeGestureRecognizerDirectionRight){
__blockCGPointpoint=self.contentView.center;
if(point.x<(self.frame.size.width-self.swiftLeftLength)) {
[UIViewanimateWithDuration:0.15animations:^{
point.x=point.x+self.swiftLeftLength;
self.contentView.center=point;
UIView*leftView=[selfviewWithTag:505];
CGRectframe=leftView.frame;
frame.origin.x=self.frame.size.width;
leftView.frame=frame;
}completion:^(BOOLfinished) {
[selfremoveLeftView];
}];
}
}
四添加左滑出来的视图
-(void)stepLeftView{
UIView*leftView=[[UIViewalloc]initWithFrame:CGRectMake(self.frame.size.width,0,self.swiftLeftLength,self.frame.size.height)];
leftView.tag=505;
[leftViewaddSubview:self.leftContentView];
[selfaddSubview:leftView];
}
五 解决cell重用机制导致的问题
- (void)prepareForReuse {
[superprepareForReuse];
[selfreset];
}
demo 下载http://download.csdn.net/detail/wjszf/7733277
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。