点击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

细节

时间: 2024-09-01 21:45:12

点击cell动态修改高度动画的相关文章

android的framework层动态修改原生输入法高度

问题描述 android的framework层动态修改原生输入法高度 framework层的修改(点击textview后,底层能动态控制输入法的高度显示) 解决方案 表达清楚,想要的效果什么样的!

解决点击cell执行动画导致的重用问题

解决点击cell执行动画导致的重用问题 说明: 动画的细节都是裸露的,并没有封装,靠看官来优化了.   效果:   源码: https://github.com/YouXianMing/UITableViewSelectedAnimation   核心: // // YouXianMingCell.h // SelectedAnimation // // Created by YouXianMing on 15/4/17. // Copyright (c) 2015年 YouXianMing.

JS动态修改iframe高度和宽度的方法_javascript技巧

本文实例讲述了JS动态修改iframe高度和宽度的方法.分享给大家供大家参考.具体如下: 如果希望通过按钮动态修改iframe的高度和宽度,可以参考下面的JS代码 <!DOCTYPE html> <html> <head> <script> function changeSize() { document.getElementById("myframe").height="300"; document.getEleme

给UITableViewCell动态调整高度

在网上看到有人如此实现动态调整高度:点击. 不至于为了获取高度创建一个不需要的cell. 主要有两个地方需要调整高度,一个是自己创建的UILabel或其它子视图,另一个就是cell的高度. cell内部的view的frame通过重写cell的layoutSubviews方法就行了,就也是一种标准做法: -(void)layoutSubviews{     [super layoutSubviews];          self.headImageView.origin = CGPointMak

js动态修改表格行colspan列跨度的方法

 这篇文章主要介绍了js动态修改表格行colspan列跨度的方法,实例分析了javascript动态修改html中table属性的技巧,具有一定参考借鉴价值,需要的朋友可以参考下     本文实例讲述了js动态修改表格行colspan列跨度的方法.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 <!DOCTYPE h

Win7系统怎么修改开机动画?

  Win7系统怎么修改开机动画?          按住"Win+R"键,打开运行对话框,在方框内输入"regedit",然后确定;如图: 在打开的注册表编辑器中依次打开 HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionAuthenticationLogonUIBackgroud ;如图: 双击"OEMBackground"并打开,把默认的数值"0"改为&quo

弹出窗口-wpf 动态改变窗口大小动画

问题描述 wpf 动态改变窗口大小动画 想做一个在指定屏幕位置弹出窗口到最大化的动画效果,弹出是要不断的改变窗口的位置和窗口的高宽.用wpf的动画效果动态改变窗体的宽度和高度,这样实现时发现显示弹出效果时不连贯,应该是改变窗口高宽时,内部的控件也随之变化而出现闪屏. 请问可以这样实现弹出效果吗?或者有什么别的办法实现弹出动画,谢谢!

利用Mono.Cecil动态修改程序集来破解商业组件(仅用于研究学习)

原文:利用Mono.Cecil动态修改程序集来破解商业组件(仅用于研究学习)      Mono.Cecil是一个强大的MSIL的注入工具,利用它可以实现动态创建程序集,也可以实现拦截器横向切入动态方法,甚至还可以修改已有的程序集,并且它支持多个运行时框架上例如:.net2.0/3.5/4.0,以及silverlight程序 官方地址:http://www.mono-project.com/Cecil      首先,我先假想有一个这样的商业组件,该组件满足了以下条件: 1. 该程序集的代码被混

hibernate3-在j2ee环境下如何实现数据库表的动态修改!

问题描述 在j2ee环境下如何实现数据库表的动态修改! 如何实现已经部署启动的应用通过前端的点击来增加或删除某个数据表的字段,有没有什么持久层框架能实现?或者jdbc? 如果表结构改了! javaBean 如何随着表结构一起修改? !!!!前提是服务器已经启动,部署成功!!!!! 急切求大神们解答!!!!!!!! 解决方案 更改表结构:execute immediate 'alter table add column **' using ** Java不是解释型语言,需要先编译才能运行. 使用h