效果:UITableView滾動(dòng)的時(shí)候會有動(dòng)畫加視差效果
一個(gè)未處理的列表.png
當(dāng)cell出現(xiàn)的時(shí)候
-(void)tableView:(UITableView *)tableView willDisplayCell:(EveryDayTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
1.cell出現(xiàn)時(shí)圖片由透明變不透明勺美,由小變大禽车,由下往上
cell的Transform3D動(dòng)畫.png
CATransform3D rotation;//3D旋轉(zhuǎn)
//y,z周偏移
rotation = CATransform3DMakeTranslation(0 ,50 ,20);
// rotation = CATransform3DMakeRotation( M_PI_4 , 0.0, 0.7, 0.4);
//x,y縮小0.9址遇,寬高縮小0.9
rotation = CATransform3DScale(rotation, 0.9, 0.9, 1);
rotation.m34 = 1.0/ -600;//參數(shù)
//設(shè)置陰影顏色和偏移量,右下偏移
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
//設(shè)置透明度為0
cell.alpha = 0;
cell.layer.transform = rotation;
//開始動(dòng)畫洪唐,可也使用block
[UIView beginAnimations:@"rotation" context:NULL];
//旋轉(zhuǎn)時(shí)間
[UIView setAnimationDuration:0.6];
//恢復(fù)到原始狀態(tài)
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
[UIView commitAnimations];
2.改變圖片的transform屬性尺锚,讓圖片不在cell中顯示完
cell層次.png
cell上的圖片偏移.png
- (CGFloat)cellOffset {
//得到cell在屏幕中的坐標(biāo)
CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
//得到cell中心y的坐標(biāo)
CGFloat centerY = CGRectGetMidY(centerToWindow);
//得到父視圖的中心點(diǎn)
CGPoint windowCenter = self.superview.center;
//得到距離差
CGFloat cellOffsetY = centerY - windowCenter.y;
NSLog(@"------%f",cellOffsetY);
//距離差/兩個(gè)父視圖高度
CGFloat offsetDig = cellOffsetY / self.superview.frame.size.height *2;
//250是cell高度,kHeight/1.7是圖片高度
CGFloat offset = -offsetDig * (kHeight/1.7 - 250)/2;
NSLog(@"%f",offset);
//這項(xiàng)就可以實(shí)現(xiàn)讓他初始向上偏移讶凉,有偏移多的有偏移少的
CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
//改變圖片的transfrom
self.picture.transform = transY;
return offset;
}
當(dāng)列表正在滾動(dòng)的時(shí)候
iOS6.gif
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//獲取可以見到的 cell,讓圖片在cell坐標(biāo)改變的時(shí)候偏移
NSArray<EveryDayTableViewCell *> *array = [self.tableView visibleCells];
[array enumerateObjectsUsingBlock:^(EveryDayTableViewCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj cellOffset];
}];
}