花式tableView

前文

tableview是一個以前從來不重視的控件,因為感覺都被封裝好了,只要調(diào)用方法就可以了,但是用的時候一直會有一些奇奇怪怪得問題,無法達(dá)到效果,所以今天決定要將遇到的問題記錄下來,當(dāng)然,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;

}

}

}


上兩個方法用于記錄動畫的效果,并不能執(zhí)行動畫,要執(zhí)行還得有一個入口執(zhí)行過后就用cell的isAnimation屬性執(zhí)行動畫并用以上兩個方法呈現(xiàn)cell的狀態(tài),所以還要在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)];

}

導(dǎo)航欄右按鈕為出口

-(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)];//度數(shù)轉(zhuǎn)弧度

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的方法是有聯(lián)系的,好好使用會優(yōu)化性能,但是我并不會,以后以待研究

待續(xù)


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容