这两天遇到一个问题,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. C#程序设计基础——类、对象、方法

    类与对象 类 类是一种构造,通过使用该构造,用户可以将其他类型的变量.方法和事件组合在一起,从而创建自定义类型.类就像一个蓝图,它定义类型的数据和行为. 对象 定义类之后,便可通过将类加载到内存中来使 ...

  2. php pack、unpack、ord 函数使用方法

    string pack ( string $format [, mixed $args [, mixed $... ]] ) Pack given arguments into a binary st ...

  3. Going Home(最小费用最大流)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16200   Accepted: 8283 Description On a ...

  4. Pie(二分)

    ime Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8930   Accepted: 3235   Special Judge De ...

  5. Pen Editor

    Pen Editor

  6. 【转】Android自定义Adapter的ListView的思路及代码

    原文网址:http://www.jb51.net/article/37236.htm Android自定义Adapter的ListView的思路及代码,需要的朋友可以参考一下   在开发中,我们经常使 ...

  7. 线段树(维护最大值):HDU Billboard

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. bzoj 2324 [ZJOI2011]营救皮卡丘(floyd,费用流)

    2324: [ZJOI2011]营救皮卡丘 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1777  Solved: 712[Submit][Stat ...

  9. 2012蓝桥杯本科组C/C++决赛题

    星期几 [结果填空] (满分5分) 1949年的国庆节(10月1日)是星期六. 今年()的国庆节是星期一. 那么,从建国到现在,有几次国庆节正好是星期日呢? 只要答案,不限手段! 可以用windows ...

  10. [Audio processing] 常见语音特征 —— LPC

    共振峰产生的原理及其在音质上的体现,共振峰的分布位置是建立在声音产生媒介的共鸣物理结构基础上的(Resonant Physical Structure).   无论是人声还是乐器,它们的声音特性都源自 ...