美文网首页
花式tableView

花式tableView

作者: XiuFi | 来源:发表于2017-02-15 15:33 被阅读28次

前文

tableview是一个以前从来不重视的控件,因为感觉都被封装好了,只要调用方法就可以了,但是用的时候一直会有一些奇奇怪怪得问题,无法达到效果,所以今天决定要将遇到的问题记录下来,当然,collectionView也是一样的


TableView

给所有的cell加效果

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

[self.cellArr addObject:cell];

//    NSMutableArray *cellsArr = self.cellArr;

if (self.isEditing == YES) {

for (productCenterViewCell *Procell in self.cellArr) {

Procell.isAnimation = YES;

Procell.deleteItem.hidden = NO;

}

}

}


- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath{

if (self.isEditing == NO) {

for (productCenterViewCell *Procell in self.cellArr) {

Procell.isAnimation = NO;

Procell.deleteItem.hidden = YES;

}

}

}


上两个方法用于记录动画的效果,并不能执行动画,要执行还得有一个入口执行过后就用cell的isAnimation属性执行动画并用以上两个方法呈现cell的状态,所以还要在cell里面重写isAnimation的set方法

我是在cell添加了长按手势为入口

-

-(void)pressGesture:(UILongPressGestureRecognizer*)gesture{

//NSArray *cellsArr = [self.choosePicture visibleCells];

NSMutableArray*cellsArr =self.cellArr;

self.isEditing=YES;

for(companyQualificationCell*cellincellsArr) {

cell.isAnimation=YES;

cell.seleteBut.hidden=NO;

}

self.navigationItem.rightBarButtonItem= [[UIBarButtonItemalloc]initWithTitle:@"取消编辑"style:0target:selfaction:@selector(cancelShake)];

}

导航栏右按钮为出口

-(void)cancelShake{

NSArray*cellsArr =self.cellArr;

for(companyQualificationCell*cellincellsArr) {

// [cell.layer removeAllAnimations];

cell.isAnimation=NO;

cell.seleteBut.hidden=YES;

}

self.navigationItem.rightBarButtonItem= [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"add"]style:0target:selfaction:@selector(add)];

self.isEditing=NO;

}

Cell的setisAnimation方法

写的是抖动的动画

-(void)setIsAnimation:(BOOL)isAnimation{

if(isAnimation ==YES) {

CAKeyframeAnimation* keyAnimaion = [CAKeyframeAnimationanimation];

keyAnimaion.keyPath=@"transform.rotation";

keyAnimaion.values=@[@(-0.5/180.0*M_PI),@(0.5/180.0*M_PI),@(-0.5/180.0*M_PI)];//度数转弧度

keyAnimaion.removedOnCompletion=NO;

keyAnimaion.fillMode=kCAFillModeForwards;

keyAnimaion.duration=0.3;

keyAnimaion.repeatCount=MAXFLOAT;

[self.layeraddAnimation:keyAnimaionforKey:@"edit"];

}else{

[self.layerremoveAnimationForKey:@"edit"];

self.seleteBut.hidden=NO;

}

}


但是那两个方法肯定好像和cellforRow的方法是有联系的,好好使用会优化性能,但是我并不会,以后以待研究

待续


相关文章

网友评论

      本文标题:花式tableView

      本文链接:https://www.haomeiwen.com/subject/mteqwttx.html