这两天遇到一个问题,UITableView中需要加入动画,而且每一行的速度不一样。

刚开始做时把所有的cell都遍历一遍加上动画,后来发现,如果数据很多时,就会出现各种各样的问题,而且没有显示在界面上的cell就没必要再用动画了,毕竟看不到。

后来发现UITableView中有这么一个方法:该方法是获取界面上能显示出来了cell。

- (NSArray *)visibleCells;

visible可见的。在当前页面中能看到cells都在这个数组中。

这样,我就根据这个数据来依次来遍历:

首先看一下这个Demo的效果:

http://my.csdn.net/my/album/detail/1718119

主要代码

 #pragma UITableView

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone; } cell.textLabel.text = [NSString stringWithFormat:@"visibleCell:%d",indexPath.row]; return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//点击效果
} - (IBAction)btnAction:(id)sender {
//获取可见cells
visibleCells = visibleTableView.visibleCells;
NSLog(@"%@",visibleCells); UIButton *button = (UIButton*)sender;
CGAffineTransform transform;
double duration = 0.2; if (button.tag == ) {
transform = CGAffineTransformMakeTranslation(-, );
}else if(button.tag == ){
for (UITableViewCell *cell in visibleCells) { [UIView animateWithDuration:duration delay: options: animations:^
{
cell.transform = CGAffineTransformIdentity; } completion:^(BOOL finished)
{ }];
duration+=0.1;
}
return;
}else{
transform = CGAffineTransformMakeTranslation(, ); }
for (UITableViewCell *cell in visibleCells) { [UIView animateWithDuration:duration delay: options: animations:^
{
cell.transform = transform; } completion:^(BOOL finished)
{ }];
duration+=0.1; } }
												

UITableView中的visibleCells的用法(visibleCells帮上大忙了)的更多相关文章

  1. 如何校验内存数据的一致性,DynamicExpresso 算是帮上大忙了

    一:背景 1. 讲故事 记的在上一家公司做全内存项目的时候,因为一些关键表会在程序 startup 的时候全量灌入到内存中,但随着时间的推移,内存和数据库的同步偶尔会出现数据差异的情况,伴随着就是运营 ...

  2. vue 中 命名视图的用法

    今天主要记录  vue中命名视图的用法 先奉上官网网址:https://router.vuejs.org/zh/guide/essentials/named-views.html 一般情况下,一个页面 ...

  3. C/C++ 中 const 修饰符用法总结

    C/C++ 中 const 修饰符用法总结 在这篇文章中,我总结了一些C/C++语言中的 const 修饰符的常见用法,供大家参考. const 的用法,也是技术性面试中常见的基础问题,希望能够帮大家 ...

  4. MJRefresh在UITableView中的使用

    前言 MJRefresh是一个好用的上下拉刷新的控件,github地址如下:https://github.com/CoderMJLee/MJRefresh 很多app都使用这个控件,我们也来了解一下它 ...

  5. [原创] 基础中的基础(二):C/C++ 中 const 修饰符用法总结

    在这篇文章中,我总结了一些C/C++语言中的 const 修饰符的常见用法,供大家参考. const 的用法,也是技术性面试中常见的基础问题,希望能够帮大家梳理一下知识,给大家一点点帮助.作者是菜鸟一 ...

  6. 转载----C/C++ 中 const 修饰符用法总结

    感谢原创作者,写的好详细.不忍错过,所以转载过来了... 原文地址: https://www.cnblogs.com/icemoon1987/p/3320326.html 在这篇文章中,我总结了一些C ...

  7. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  8. ecshop中foreach的详细用法归纳

    ec模版中foreach的常见用法. foreach 语法: 假如后台:$smarty->assign('test',$test); {foreach from=$test item=list ...

  9. matlab中patch函数的用法

    http://blog.sina.com.cn/s/blog_707b64550100z1nz.html matlab中patch函数的用法——emily (2011-11-18 17:20:33) ...

随机推荐

  1. QVariant(相当于是Java里面的Object,起到一个数据类型“擦除”的作用,可以使用Q_DECLARE_METATYPE进行注册)

    =QVariant= [%这个类型相当于是Java里面的Object,它把绝大多数Qt提供的数据类型都封装起来,起到一个数据类型“擦除”的作用.比如我们的 table单元格可以是string,也可以是 ...

  2. Hadoop环境搭建-入门伪分布式配置(Mac OS,0.21.0,Eclipse 3.6)

    http://www.linuxidc.com/Linux/2012-10/71900p2.htm http://andy-ghg.iteye.com/blog/1165453 为Mac的MyEcli ...

  3. 1031. Hello World for U (20) PAT

    题目:http://pat.zju.edu.cn/contests/pat-a-practise/1031 分析: 简单题,调整数组的输出次序就可以了. 输入数组长度为len.n1 = n3 = (l ...

  4. awk文本处理--二维数组使用一例

    群友出的题: 原始文件: $ cat fileBJ30 26BJ30 24BJ30 63BJ30 70SH41 21SH41 30SH41 25SH41 25SH41 29SD15 34SD15 46 ...

  5. 【模拟】Codeforces 691A Fashion in Berland

    题目链接: http://codeforces.com/problemset/problem/691/A 题目大意: n个数0或1,要求恰好n-1个1,如果n为1则那个数一定要是1 题目思路: [模拟 ...

  6. Tangled in Cables(Kruskal+map容器处理字符串)

    /** 题意:     给你两个城市之间的道路(无向图),求出需要的     电缆.如果大于所提供的,就输出Not enough ...     否则输出所需要的电缆长度.       输入:N (给 ...

  7. lightoj 1251 (Two_Sat)

    #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #inclu ...

  8. poj2318 水题(二分+叉积)

    题目链接:http://poj.org/problem?id=2318 #include<cstdio> #include<cstring> #include<cmath ...

  9. angularjs简单实现$http.post(CORS)跨域及$http.post传参方式模拟jQuery.post

    1.开启angularjs的CORS支持 .config(function($httpProvider) { // CORS post跨域配置 $httpProvider.defaults.useXD ...

  10. boost------bind的使用(Boost程序库完全开发指南)读书笔记

    bind是c++98标准库中函数适配器bind1st/bind2nd的泛化和增强,可以适配任意的可调用类型,包括函数指针.函数引用.成员函数指针和函数对象. 1.工作原理 bind并不是一个单独的类或 ...