点击cell动态修改高度动画

简介:

点击cell动态修改高度动画


 

效果

 

源码

https://github.com/YouXianMing/Animations

//
//  TapCellAnimationController.m
//  Animations
//
//  Created by YouXianMing on 16/4/8.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "TapCellAnimationController.h"
#import "ShowTextCell.h"
#import "ShowTextModel.h"
#import "CellDataAdapter.h"
#import "UIFont+Fonts.h"
#import "UIView+SetRect.h"

@interface TapCellAnimationController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView    *tableView;
@property (nonatomic, strong) NSMutableArray *datasArray;

@end

@implementation TapCellAnimationController

- (void)setup {
    
    [super setup];
    
    [self createDataSource];
    
    [self buildTableView];
}

#pragma mark - DataSource

- (void)createDataSource {
    
    self.datasArray = [NSMutableArray array];
    
    NSArray *strings = @[
                         @"AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of the Foundation URL Loading System, extending the powerful high-level networking abstractions built into Cocoa. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use. Perhaps the most important feature of all, however, is the amazing community of developers who use and contribute to AFNetworking every day. AFNetworking powers some of the most popular and critically-acclaimed apps on the iPhone, iPad, and Mac. Choose AFNetworking for your next project, or migrate over your existing projects—you'll be happy you did!",
                         
                         @"黄色的树林里分出两条路,可惜我不能同时去涉足,我在那路口久久伫立,我向着一条路极目望去,直到它消失在丛林深处。但我却选了另外一条路,它荒草萋萋,十分幽寂,显得更诱人、更美丽,虽然在这两条小路上,都很少留下旅人的足迹,虽然那天清晨落叶满地,两条路都未经脚印污染。呵,留下一条路等改日再见!但我知道路径延绵无尽头,恐怕我难以再回返。也许多少年后在某个地方,我将轻声叹息把往事回顾,一片树林里分出两条路,而我选了人迹更少的一条,从此决定了我一生的道路。",
                         
                         @"タクシー代がなかったので、家まで歩いて帰った。もし事故が発生した场所、このレバーを引いて列车を止めてください。(丁)为了清楚地表示出一个短语或句节,其后须标逗号。如:この薬を、夜寝る前に一度、朝起きてからもう一度、饮んでください。私は、空を飞ぶ鸟のように、自由に生きて行きたいと思った。*****为了清楚地表示词语与词语间的关系,须标逗号。标注位置不同,有时会使句子的意思发生变化。如:その人は大きな音にびっくりして、横から飞び出した子供にぶつかった。その人は、大きな音にびっくりして横から飞び出した子供に、ぶつかった。",
                         
                         @"Two roads diverged in a yellow wood, And sorry I could not travel both And be one traveler, long I stood And looked down one as far as I could To where it bent in the undergrowth; Then took the other, as just as fair, And having perhaps the better claim, Because it was grassy and wanted wear; Though as for that the passing there Had worn them really about the same, And both that morning equally lay In leaves no step had trodden black. Oh, I kept the first for another day! Yet knowing how way leads on to way, I doubted if I should ever come back. I shall be telling this with a sigh Somewhere ages and ages hence: Two roads diverged in a wood, and I- I took the one less traveled by, And that has made all the difference. ",
                         
                         @"Star \"https://github.com/YouXianMing\" :)"
                         ];
    
    for (int i = 0; i < strings.count; i++) {
        
        ShowTextModel *model = [[ShowTextModel alloc] init];
        model.inputString    = strings[i];
        
        [model calculateTheNormalStringHeightWithStringAttribute:@{NSFontAttributeName : [UIFont HeitiSCWithFontSize:14.f]} fixedWidth:Width - 20];
        [model calculateTheExpendStringHeightWithStringAttribute:@{NSFontAttributeName : [UIFont HeitiSCWithFontSize:14.f]} fixedWidth:Width - 20];
        
        CellDataAdapter *adapter = [CellDataAdapter cellDataAdapterWithCellReuseIdentifier:@"ShowTextCell" data:model
                                                                                cellHeight:model.normalStringHeight
                                                                                  cellType:kShowTextCellNormalType];
        [self.datasArray addObject:adapter];
    }
}

#pragma mark - UITableView

- (void)buildTableView {
    
    self.tableView                = [[UITableView alloc] initWithFrame:self.contentView.bounds];
    self.tableView.delegate       = self;
    self.tableView.dataSource     = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableView registerClass:[ShowTextCell class] forCellReuseIdentifier:@"ShowTextCell"];
    [self.contentView addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.datasArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CellDataAdapter *dataAdapter = self.datasArray[indexPath.row];
    
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:dataAdapter.cellReuseIdentifier];
    cell.data        = dataAdapter.data;
    cell.dataAdapter = dataAdapter;
    cell.tableView   = tableView;
    cell.indexPath   = indexPath;
    [cell loadContent];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ShowTextCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell changeState];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CellDataAdapter *dataAdapter = self.datasArray[indexPath.row];
    
    return dataAdapter.cellHeight;
}

@end

细节

目录
相关文章
|
6月前
layer根据内容动态改变窗口高度
layer根据内容动态改变窗口高度
|
7月前
|
前端开发 JavaScript 容器
JavaScrpit如何实现弹出遮罩层后将页面固定到当前位置且无法继续滚动
JavaScrpit如何实现弹出遮罩层后将页面固定到当前位置且无法继续滚动
29 0
PyQt5 技术篇-QTableWidget表格组件指定行的隐藏与显示控制实例演示,设置表格指定列的列宽方法
PyQt5 技术篇-QTableWidget表格组件指定行的隐藏与显示控制实例演示,设置表格指定列的列宽方法
596 0
PyQt5 技术篇-QTableWidget表格组件指定行的隐藏与显示控制实例演示,设置表格指定列的列宽方法
|
5月前
【sgDragSize】自定义组件:自定义拖拽修改DIV尺寸组件,适用于窗体大小调整
【sgDragSize】自定义组件:自定义拖拽修改DIV尺寸组件,适用于窗体大小调整
|
7月前
|
敏捷开发 前端开发 开发者
【RaETable】🚀🚀🚀告别Form,RaETable表格列宽度支持拖动调整了,附带原理说明
【RaETable】🚀🚀🚀告别Form,RaETable表格列宽度支持拖动调整了,附带原理说明
|
10月前
|
前端开发 JavaScript
echarts tooltip设置正常却无法显示被遮挡设置层级堆叠顺序的问题解决方案
echarts tooltip设置正常却无法显示被遮挡设置层级堆叠顺序的问题解决方案
263 0
|
编解码 前端开发 UED
每日一学—设置页面文字大小随屏幕大小变化而变化(rem布局)
每日学一点加强技术水平,夯实基础。 阅读这篇文章,一起学习rem布局吧。
282 0
每日一学—设置页面文字大小随屏幕大小变化而变化(rem布局)
|
人工智能 C#
c#中在datagridview的表格动态增加一个按钮方法
c#中在datagridview的表格动态增加一个按钮方法,如果想要这一套教程的可以移步去这里 《期末作业C#实现学生宿舍管理系统》,对了最近我们有一个人工智能交流群,如果大家对代码有问题,想交流的可以进群,私聊我就可以了! 效果图片 : 在Load事件中写入代码 那ui有了功能怎么办呢?别急我们在 dataGridView1_CellContentClick事件中添加方法 这样的话 我们就可以点击对应行的修改来获取到id的值这里有一个bug就是第三行没数据需要隐藏,现在还没有解决,欢迎大家指出!.....
564 0
c#中在datagridview的表格动态增加一个按钮方法
|
Web App开发 移动开发 JavaScript
range滑块自定义样式,步骤详解以及实际应用
写在前面: 本文的主要内容包括:type="range"属性介绍,修改range默认css样式以及在js中的实际应用。本文面向前端小白,写的不好之处,请多多见谅。文末有demo链接,可以自行复制到本地进行试验。 相关:自定义 range radio select的样式滑轮,按钮,选择框 最终要实现的效果: 步骤: 1.range属性相关介绍 2.搭建html结构; 3.css样式修改,包括给滑动轨道添加样式、给滑块添加样式; 4.添加相关js代码实现应用效果; 5.关于浏览器兼容。 在html里面输入如下内容,即可使用: <input type="range">//这是最粗糙的使用方式
830 0
range滑块自定义样式,步骤详解以及实际应用