这两天遇到一个问题,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. ExtJs3常用控件操作实例

    结合工作内容,不定期更新.这里面可能会讲到一些常用的组件的操作. json: { "total": 30, "data": [{ "funcAlign ...

  2. SharePoint 2013 WebTemplates

    SharePoint 2013 WebTemplates You are here: Home / SharePoint 2013 WebTemplates   January 24, 2013 Ta ...

  3. jquery升级换代

    其实从去年开始1.9以上新版的jquery已不再支持toggle方法和live方法. live用on方法替代. 话说这个方法确实挺方便的,那么怎么交替点击呢,html的checked属性我觉得不是很好 ...

  4. 【HDOJ】2144 Evolution

    并查集+DP. /* 2144 */ #include <cstdio> #include <cstring> #include <cstdlib> #define ...

  5. Paths on a Grid

    http://poj.org/problem?id=1942 题意:一个n*m的格子,从左下角走到右上角有多少种走法,规定只能向上或向右走: 思路:解法挺水的,高中学组合数的时候老师给讲过:求C[m+ ...

  6. IIS6.0部署asp.net网站步骤图解

    IIS 发布步骤 1, 程序->运行->输入inetmgr,打开IIS管理器; 2, 展开左侧树形目录->右击“网站”->新建->网站,打开网站创建向导; 3, 点击“下 ...

  7. Python根据上下限生成不重复随机数

    Python 2.7.5 代码: # coding=gbk import random import sys min_num = input('输入下限:') max_num = input('输入上 ...

  8. 使用XRDP实现Windows远程桌面Linux系统

    一般情况下我们用ssh客户端远程登陆Linux系统,至于图形界面下的linux远程登陆工具,我们一般都会想到vnc,但它的安全性不够,在这里,我将介绍XRDP的安装配置方法.我们可以很方便的通过Win ...

  9. 重载(Overloading)以及模板(Template)

    继续<C++ premier plus>的学习 (1)函数重载,通俗来说,就是相同的函数名字名下,存在多个函数,要使得这成立,各个同名函数必须形参列表(也称为"签名", ...

  10. Jenkins 八: 构建Git项目

    1. 安装git. http://git-scm.com/download/win 下载之后一步步安装即可.   2. 安装插件. 打开"系统管理" –> "管理插 ...