zoukankan      html  css  js  c++  java
  • UI基础--封装cell滑动时的动画

    新建一个类:CellDisplay:NSObject

    .h
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    
    @interface CellDisplay : NSObject
    
    +(void)tableView:(UITableView *)tableView cell:(UITableViewCell *)cell IndexPath:(NSIndexPath *)indexPath;
    
    
    @end
    .m
    
    #import "CellDisplay.h"
    
    @implementation CellDisplay
    
    +(void)tableView:(UITableView *)tableView cell:(UITableViewCell *)cell IndexPath:(NSIndexPath *)indexPath
    {
        
        NSArray *array =  tableView.indexPathsForVisibleRows;
        NSIndexPath *firstIndexPath = array[0];
        
        //设置anchorPoint
        cell.layer.anchorPoint = CGPointMake(0, 0.5);
        //为了防止cell视图移动,重新把cell放回原来的位置
        cell.layer.position = CGPointMake(0, cell.layer.position.y);
        
        //设置cell 按照z轴旋转90度,注意是弧度
        if (firstIndexPath.row < indexPath.row) {
            cell.layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1.0);
        }else{
            cell.layer.transform = CATransform3DMakeRotation(- M_PI_2, 0, 0, 1.0);
        }
        
        cell.alpha = 0.0;
        
        [UIView animateWithDuration:1 animations:^{
            cell.layer.transform = CATransform3DIdentity;
            cell.alpha = 1.0;
        }];
        
        
        //CollectionCell 动画
        /*
         if (indexPath.row % 2 != 0) {
         cell.transform = CGAffineTransformTranslate(cell.transform, kScreenWidth/2, 0);
         }else{
         cell.transform = CGAffineTransformTranslate(cell.transform, -kScreenWidth/2, 0);
         }
         cell.alpha = 0.0;
         [UIView animateWithDuration:0.7 animations:^{
         cell.transform = CGAffineTransformIdentity;
         cell.alpha = 1.0;
         } completion:^(BOOL finished) {
         
         }];
         */
        
    }
    
    @end

    在tableview的协议方法中调用即可:

    - (void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath
    {
        
        [CellDisplay tableView:tableView cell:cell IndexPath:indexPath];
        
    }

    Ok...

  • 相关阅读:
    GCD实现多个定时器,完美避过NSTimer的三大缺陷(RunLoop、Thread、Leaks)
    iOS适配UIViewView/WKWebView,H5生成长图,仿微信进度条
    翻译jquery官方的插件制作方法
    javascript引用和赋值
    薯片公司真实JS面试题(乐视TV)
    caller、call、apply、callee的用法和意思
    常用javascript类型判断
    Git 常用命令笔记(不定期持续记录)
    sublime text2 emmet 安装
    hash"#"
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5858669.html
Copyright © 2011-2022 走看看