UITableViewCell動(dòng)畫(huà)

當(dāng)cell將要顯示時(shí)調(diào)用

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

函數(shù),可以在這里進(jìn)行Cell內(nèi)子控件屬性的修改,完成所需要的動(dòng)畫(huà)效果。

cell動(dòng)畫(huà).gif

代碼:

@property (assign, nonatomic) CGFloat lastScrollOffset;
@property (assign, nonatomic) CGFloat move;
- (void)viewDidLoad {
    [super viewDidLoad];
    _move = [UIScreen mainScreen].bounds.size.width;
    _lastScrollOffset = 0;
}

下拉和上拖動(dòng)畫(huà)加載的方向不同,先判斷手勢(shì)的的方向

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView != self.tableview) return;
    CGFloat y = scrollView.contentOffset.y;
    if (y > _lastScrollOffset) {//用戶往上拖動(dòng)
        _move = [UIScreen mainScreen].bounds.size.width;
    } else {//用戶往下拖動(dòng)
        _move = -[UIScreen mainScreen].bounds.size.width;
    }
    //存儲(chǔ)最后的y值
    _lastScrollOffset = y;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger baseRows = ceilf(CGRectGetHeight(self.tableview.bounds) / 100) - 1;
    CGFloat delay = indexPath.row <= baseRows ? 0.05f * indexPath.row : 0.01f;
    cell.alpha = 0.0;
    cell.transform = CGAffineTransformIdentity;
    CGFloat xMove = _move;
    cell.transform = CGAffineTransformMakeTranslation(xMove, 0);
    
    [UIView animateWithDuration:1.0f delay:delay usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        cell.alpha = 1.0;
        cell.transform = CGAffineTransformMakeTranslation(0, 0);
    } completion:^(BOOL finished) {
        
    }];
}

NSInteger baseRows = ceilf(CGRectGetHeight(self.tableview.bounds) / 100) - 1;中的100是cell的高度。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容