前文
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ù)