Table View Animations Tutorial: Drop-In Cards

relay_subgraph_partition_one_slide.pptx 立即下载

The standard UITableView is a powerful and flexible way to present data in your apps; chances are that most apps you write will use UITableView in some form. However, one downside is that without some level of customization, your apps will look bland and blend in with the thousands of apps just like it.

To prevent boring table views, you can add some subtle animation to liven up the actions of your app. You may have seen this in the popular app Google Plus, where the cards fly in through the side with a cool animation. If you haven’t seen it yet, download it now to check it out (it’s free)!

In this table view animations tutorial, you’ll be enhancing an existing app to rotate the cells of a table as you scroll through. Along the way, you’ll learn about how transforms are achieved in UIKit, and how to use them in a subtle manner so as not to overwhelm your user with too much happening on-screen at once.

This tutorial assumes you know how to work with a UITableView. If you’re not really familiar with table views, you might want to start with a tutorial such as How to Create a Simple iPhone App that will teach you the basics of a TableView app.

Note from Ray: Full credit for this technique goes to  Orta Therox, the newest member of our new “Code Team” at raywenderlich.com. Orta created the original sample project which Brian then polished and converted into this tutorial.

The Code Team is a group of expert-level coders interested in coming up with particularly cool demos demonstrating advanced techniques. The Tutorial Team then converts the best demos into high quality tutorials. If you are an expert level iOS developer and are interested in joining the Code Team, contact me!

Getting Started

Download the starter project and open it up in Xcode. You’ll find a simple storyboard project with aUITableViewController subclass (CTMainViewController) and a custom UITableViewCell (CTCardCell). The cell has all the properties that you need to set the data for each individual.

Build and run the project in the simulator; you’ll see the following:

Starter project

A perfectly good design, ready to be spiced up.

The app is off to a good start, but it could use a little more flair. That’s your job; you’ll use some Core Animation tricks to animate your cell.

Defining Your Transformation

You’ll add a rotation effect to your cards to make your app feel a little more dynamic. Core Animation can be used with all elements of UIKit, and some incredibly intricate things can be built using this framework. Although it’s incredibly powerful, there are some portions of it that are tremendously simple to implement.

To get your cards rotating, you’ll apply a transformation to the cell as it is displayed, and then animate it so that it returns to its normal position. Since this transformation will be applied to each row, there’s no sense regenerating the animation for every cell. Instead, you’ll store the animation in a property so that you can reuse it.

Open CTMainViewController.m and add the following property to the @interface block:

@property (assign, nonatomic) CATransform3D initialTransformation;

The code above sets up the property to store your animation.

Next, add the following code to viewDidLoad, immediately after changing the backgroundView:

CGFloat rotationAngleDegrees = -15;
CGFloat rotationAngleRadians = rotationAngleDegrees * (M_PI/180);
CGPoint offsetPositioning = CGPointMake(-20, -20);
 
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DRotate(transform, rotationAngleRadians, 0.0, 0.0, 1.0);
transform = CATransform3DTranslate(transform, offsetPositioning.x, offsetPositioning.y, 0.0);
_initialTransformation = transform;


The code above first sets up a few CGFloat and CGPoint constants to be used in the transformations. Next, it applies a series of simple transformations and translations to build up the effect, as follows:

  • Start with an identity transform, which is a fancy math term for “do nothing.”
  • Call CATransform3DRotate to apply a rotation of -15 degrees (in radians), where the negative value indicates a clockwise rotation.
  • Apply the rotation around the axis 0.0, 0.0, 1.0; this represents the z-axis, where x=0, y=0, and z=1.
  • Applying just the rotation to the card isn’t enough, as this simply rotates the card about its center. To make it look like it’s tipped over on a corner, add a translation or shift where the negative values indicate a shift up and to the left.

Note: The transformation ultimately is a complicated matrix. If you studied matrix math in school, you may recognize this as multiplication of matricies. Each step multiplies a new transformation until you end up with the final matrix.

Building up transformations

Building up transformations to produce the desired effect.

The transformation is now stored in a property; to see it in action, you need to apply it to your cards.

Applying Your Transformation

First, you’ll just apply the initial transformation to the cells to tip them on their side. You’ll worry about the reverse transformation — returning the cells to their original position — in just a bit.

Add the following line to import section at the top of CTMainViewController.m:

#import <QuartzCore/QuartzCore.h>


Next, add the following method to the implementation section of CTMainViewController.m:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *card = [(CTCardCell* )cell mainView];
 
    card.layer.transform = self.initialTransformation;
    card.layer.opacity = 0.8;        
}


TableView calls tableView:willDisplayCell:forRowAtIndexPath on its delegate just before each cell is displayed. The above method grabs a reference to the subview named mainView defined in CTCardCell. Thelayer property of the UIView elements hold a reference to the Core Animation layer for the view; in turn, layers have a transform property.

By default, transform is set to the identity transform, but here you override this and set the transform to the one you just stored in the property. Finally you set the initial opacity of the layer to 0.8 to look slightly transparent; as the animation progresses you’ll fade the card in to an opacity of 1.0 — which you’ll take care of a little later.

You’ll notice that you’re transforming a child view of the cell, and not the cell itself. Rotating the actual cell would cause part of it to cover the cell above and below it, which would cause some odd visual effects, such as flickering and clipping of the cell. This is why the cell has a large view (mainView) containing all the other items.

Before you build the project, you’ll need to link the framework into the project to see your hard work in action.

Click the CardTilt target in the navigator section on the left of the XCode window. Click Build Phases, then expand the little triangle next to ‘Link Binary with Libraries’. Click the small ‘+’ at the bottom of that section, and add QuartzCore.framework to the build.

Since you don’t want to leave the cells with this crooked alignment, go ahead with the next section before you run the project.

Things Fall Into Place

Core Animation provides a great mechanism to create simple animations in your applications. All you have to do is provide a starting point, as you did above with your initial transform, and an ending point, which you’ll do below, and Core Animation figures out the steps along the way.

To define the end point for your animation, add the following code totableView:willDisplayCell:forRowAtIndexPath in CTMainViewController.m file just after the point where you set the initial layer properties:

[UIView animateWithDuration:0.4 animations:^{
        card.layer.transform = CATransform3DIdentity;
        card.layer.opacity = 1;
    }];


In the code above, the animateWithDuration parameter represents the length of the transition in seconds. To make the animation run faster or slower, simply change this value.

When you’re debugging animations, it’s helpful to make your animation really long, like four or five seconds; this way you can catch little things that escape your notice when the animation runs at normal speed, such as clipping issues with the cell frame — or perhaps to grab a screenshot when writing a tutorial! :]

Next, you apply the CATransform3DIdentity transformation to bring your cell back to its original position. Finally, you animate the opacity of the cell back to 1.0; this will provide the “fade-in” effect you started earlier when you set the initial opacity to 0.8.

Note: Core Animation provides a block syntax where you declare the final condition of your animation sequence and how long it should take. The framework figures out the details for you. If you are new to blocks, see How To Use Blocks in iOS 5 (part 1 and part 2).

If you’re interested in the “why” and “how” of block syntax, Nils Hayat wrote a really great article which explains how to get from C declarators to Objective-C block syntax.

Build and run your application; scroll through the list and the cells of your table now rotate into place as they appear on the screen.

Rotation of card cell.

Not all properties support animation; the Core Animation Programming Guide provides a list of animatable properties for your reference.

Adding Some Limits to Your Transformation

Although the animation effect is neat, you’ll want to use it sparingly. If you’ve ever suffered through a presentation that overused sound effects or animation effects, then you know what effect overload feels like!

In your project, you only want the animation to run the first time the cell appears — as it scrolls in from the bottom. When you scroll back toward the top of the table, the cells should scroll without animating.

You need a way to keep track of which cards have already been displayed so they won’t be animated again. To do this, you’ll use a collection called a set.

Note: A set is an unordered collection of unique entries with no duplicates, while an array is an ordered collection that does allow duplicates. The Foundation collection classes NSSet and NSArray handle these two collections for you.

In your case, you just need a collection to hold the cells that have already been displayed; using an array leads to a more complicated implementation as you’d need to look up every card to see it it was already in the array, or you’d need to insert cards multiple times as the user scrolled up and down the table.

The general disadvantage of a set is that it doesn’t guarantee an order, but the ordering of your cells is already handled by the table datasource, so it isn’t an issue in this case.

Add the following code to the interface definition section of CTMainViewController.m:

@property (nonatomic, strong) NSMutableSet *shownIndexes;


Next, add the following code to viewDidLoad in CTMainViewController.m:

_shownIndexes = [NSMutableSet set];


Finally, modify tableView:willDisplayCell:forRowAtIndexPath: in CTMainViewController.m as follows:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (![self.shownIndexes containsObject:indexPath]) {
        [self.shownIndexes addObject:indexPath];
 
        UIView *card = [(CTCardCell* )cell mainView];
 
        card.layer.transform = self.initialTransformation;
        card.layer.opacity = 0.8;
 
        [UIView animateWithDuration:0.4 animations:^{
            card.layer.transform = CATransform3DIdentity;
            card.layer.opacity = 1;
        }];        
    }
}


In the code above, instead of animating every cell each time it appears as you scroll up and down the table, you check to see if indexPath is contained in the set you defined earlier. If the indexPath is not in the set, this is the first time the cell has been displayed; therefore you transform the initial position, run the animation, then add the indexPath to the set. If it was already in the set, then you don’t need to do anything at all.

Build and run your project; scroll up and down the tableview and you’ll only see the cards animate the first time they appear on-screen.

Where To Go From Here?

Now that you’ve covered the basics of adding animation to cells, try changing the values of your transform to see what other effects you can achieve. Some suggestions are:

  1. Faster or slower animation
  2. Larger rotation angle
  3. Different offsets; if you change the rotation angle, you will likely need to change the offset to make the animation look right. What does the animation look like if you drop the offset entirely and use 0,0 for the parameters?
  4. Go nuts and create some whacked-out transforms.
  5. Advanced:Can you get the card to rotate along the horizontal or vertical axis? Can you make it look like it flips over completely?
  6. Advanced:Add an else clause to tableView:willDisplayCell:forRowAtIndexPath: and perform a different animation when cells are displayed a second time.
Crazy Rotations

Crazy rotations that you can (but maybe shouldn’t) apply to your cells. See if you can duplicate these!

A great exercise is to try and identify animations in your favorite apps. Even with the simple animation from this tutorial, there are countless variations you can produce on this basic theme. Animations can be a great addition to user actions, such as flipping a cell around when selected, or fading in or out when presenting or deleting a cell.)

If you want to see this technique in a slightly different context, check out UIView Tutorial for iOS: How To Use UIView Animation.

Again, a big thank you goes to Orta Therox for the original implementation of this code. Anything clever in the animation is from Orta, the sloppy parts are from myself.

From: http://www.raywenderlich.com/49311/advanced-table-view-animations-tutorial-drop-in-cards


不会出现 服务器正在连接 的搜索器 立即下载

相关推荐

3.react-state-notes.zip

3.react-state-notes.zip

一个免费的激光打标软件的配套硬件说明

激光打标软件配套硬件说明

triton-inference-server-ge-backend

新版本特性 v2.3.0 支持对全局、session、graph 的options进行添加,从而进一步调优模型,相关案例请参考 性能调优方法论。 支持采用分档模式将符合条件模型转化为静态图,提高吞吐性能。 补充如何采用分档模式+锁核+调整精度,进一步提高性能。 在AscendHub下载镜像时需确认好版本,若使用旧版本镜像,需要手工下载源码编译生成新的backend后才能支持新特性。 版本特性 v2.2.0 支持从onnx文件读取模型输入输出信息, config中若无指定input,output,将会自动从文件中读取; 调整动态图在多实例下使用多Session方式,提高并发吞吐(显存占用会增高); 支持动态batch场景小batch动态合并特性,配合多Session,提高吞吐; 补充调优方法论以及cnclip模型的最佳实践; 支持多模型特性,可支持同时拉起多个模型,提高显存利用率; 支持非0轴动态shape场景; 支持TensorFlow的pb文件。

高校技术转移办公室人员如何利用知识图谱技术提升科技成果评价的科学性与高效性?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

2007-2025年36家商业银行绿色信贷余额数据(2025年无缺失)

1、指标覆盖区间为2007年至2025年 2、数据取自各银行年度报告及社会责任报告 3、核心指标为绿色信贷余额 4、涉及银行包括:苏农银行、中国银行、紫金银行、杭州银行、华夏银行、邮储银行、青岛银行、兴业银行、苏州银行、农业银行、宁波银行、上海银行、江阴银行、招商银行、长沙银行、北京银行、无锡银行、民生银行、浙商银行、常熟银行、成都银行、工商银行、郑州银行、光大银行、南京银行、建设银行、浦发银行、贵阳银行、渝农商行、西安银行、交通银行、江苏银行、中信银行、张家港行、平安银行、青农商行

2019-2026年 中国分行业进出口数据 xlsx

数据整理中国各细分行业海关进出口数据,包括中国对各个国家进口、出口数据,中国各个行业进出口数据,各国贸易数据是了解每个国家市场的最基础和重要信息。数据非面板数据,时间、行业分类有缺失。 标 日期 采购商国家/地区 供应商国家/地区 采购商 供应商 采购商地址 供应商地址 通知人 通知人地址 制造商 原产国 目的国 起运港 目的港 HS编码 产品描述 唛头 数量 数量单位 重量 金额($) 单号 集装箱号 品牌

国央企创新负责人在推动内部技术转化时,如何确保服务流程的合规与可控?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

2000-2024年 各地区结婚、离婚、再婚等数据-各地区 xlsx

一般来说,经济发达地区的结婚和离婚率相对较高,而经济欠发达地区的结婚和离婚率相对较低。此外,不同省份的文化、习俗、社会观念等因素也会对结婚和离婚情况产生影响。 本数据从2000年至2024年,对各地区的结婚、离婚及再婚情况进行了全面统计。通过对这些数据的深入分析,我们可以洞察婚姻趋势的演变轨迹,以及地区之间的差异性。这些数据不仅反映了人们的婚姻选择、家庭形态的变化,还揭示了社会动态的演变。对于研究家庭结构和社会变迁的学者而言,这份数据提供了宝贵的参考依据和信息。 相关数据 年份 地区 行政区划代码 所属地域 年末常住人口(万人) 人口出生率(‰) 人口死亡率(‰) 15岁及以上人口数(人口抽样调查)(人) 15岁及以上男性人口数(人口抽样调查)(人) 15岁及以上女性人口数(人口抽样调查)(人) 15岁及以上未婚人口数(人口抽样调查)(人) 15岁及以上男性未婚人口数(人口抽样调查)(人) 15岁及以上女性未婚人口数(人口抽样调查)(人) 15岁及以上初婚有配偶人口数(人口抽样调查)(人) 15岁及以上男性初婚有配偶人口数(人口抽样调查)(人) 15岁及以上女性初婚有配偶人口数(人口抽样调查)(人) 15岁及以上再婚有配偶人口数(人口抽样调查)(人) 15岁及以上男性再婚有配偶人口数(人口抽样调查)(人) 15岁及以上女性再婚有配偶人口数(人口抽样调查)(人) 15岁及以上离婚人口数(人口抽样调查)(人) 15岁及以上男性离婚人口数(人口抽样调查)(人) 15岁及以上女性离婚人口数(人口抽样调查)(人) 15岁及以上丧偶人口数(人口抽样调查)(人) 15岁及以上男性丧偶人口数(人口抽样调查)(人) 15岁及以上女性丧偶人口数(人口抽样调查)(人) 15岁及以上有配偶人口数(人口抽样调查)(人) 15岁及以上男性有配偶人口数(人口抽样调查)(人) 15岁及以上女性有配偶人口数(人口抽样调查)(人) 结婚登记(万对) 内地居民登记结婚(万对) 内地居民初婚登记(万人) 内地居民再婚登记(万人) 涉外及港澳台居民登记结婚(万对) 离婚登记(万对) 粗离婚率(‰)

国央企在推动创新成果转化时,如何保障技术交易流程的合规性与可追溯性?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

后端开发 Docker4.99.0 AppleSilicon 苹果芯片 Mac 安装包

本资源为 Docker Desktop 4.99.0 苹果芯片(Apple Silicon)专用安装包,原生适配 M 系列 Mac,可快速搭建本地容器开发环境,支持镜像拉取、容器编排、项目打包部署。适合后端开发、运维、全栈开发者,用于本地微服务、测试环境、项目容器化开发。

milvus-v2.6.25镜像文件

milvus-v2.6.25镜像文件

科技中介服务机构在进行技术需求挖掘时,如何避免遗漏关键信息并提高匹配精准度?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

医学信息影像AI临床采纳的责任边界研究:基于场景选点与流程嵌入的分步实施路径

内容概要:本文以“影像人工智能(CAD)的临床采纳与责任边界”为核心议题,指出当前影像AI的发展瓶颈已从技术准确性转向“谁负责、怎么用”的机制与治理问题。通过文献研究与政策文本分析,文章系统梳理了CAD的应用场景与效果、临床采纳障碍及责任边界划分三大问题,揭示出“假阳性导致医生信任下降、责任归属不清、采购与使用脱节”三重瓶颈相互强化的闭环结构,并提出“场景选点—试用验证—责任规则先行—流程嵌入”的分步递进式建设路径,强调需通过机制闭环实现技术真正落地。; 适合人群:从事医疗信息化管理、医学人工智能研究、医院运营管理及相关政策制定的专业人员,以及医学信息学、卫生管理专业的高年级本科生与研究生。; 使用场景及目标:①用于医疗机构评估影像AI引入的可行性与实施路径,避免资源错配;②为政策制定者提供优化考核机制与责任界定的理论依据;③帮助AI厂商理解临床真实需求,提升产品与流程的契合度;④作为学术研究框架,支持对技术采纳与治理机制的深入探讨。; 阅读建议:本文构建了“现状—机制—治理”三层分析框架,建议读者结合自身角色聚焦不同章节:管理者重点关注第五章路径设计,研究者关注第三章文献述评与第六章研究展望,实施者关注第四章瓶颈分析与实施保障。阅读时应特别注意概念的操作化定义与证据等级区分,避免将理论推导误作实证结论,并在应用时结合本地实际进行裁剪与验证。

期权五档行情数据包含交易时间(精确至毫秒)、合约代码、买一至买五价格及数量、卖一至卖五价格及数量,同时记录最新价、成交量与持仓量 分钟级别行情数据为逐分钟合成的K线,字段包括时间、合约代码、开盘价、最

期权五档行情数据包含交易时间(精确至毫秒)、合约代码、买一至买五价格及数量、卖一至卖五价格及数量,同时记录最新价、成交量与持仓量。分钟级别行情数据为逐分钟合成的K线,字段包括时间、合约代码、开盘价、最高价、最低价、收盘价、成交量、成交额和持仓量。 数据源:CMES金融数据库

推动企业技术需求与高校科研成果对接,需要哪些关键支撑要素?.docx

推动企业技术需求与高校科研成果对接,需要哪些关键支撑要素?

科技中介服务机构如何高效开展技术需求挖掘与分析?.docx

科技中介服务机构如何高效开展技术需求挖掘与分析?

三电平维也纳VIENNA双闭环控制整流器仿真(Simulink仿真实现)

内容概要:本文档系统性地介绍了以“三电平维也纳VIENNA双闭环控制整流器”为核心的电力电子系统Simulink仿真资源,聚焦于电压电流双闭环控制、中点电位平衡、空间矢量脉宽调制(SVPWM)等关键技术的建模与实现。资源包不仅提供完整的仿真模型,还配套Mathcad计算书、设计报告及参考文献,帮助用户从理论推导到参数设计再到仿真验证实现全流程贯通。同时,文档整合了大量相关拓扑(如DAB、LLC、PFC、CLLC等)与先进控制策略(如EPS调制、软开关、最小应力优化、模型预测控制等)的仿真案例,覆盖从基础整流器到复杂双向变换系统的多个典型应用场景,构成一个面向科研、教学与工程实践的综合性学习体系。; 适合人群:具备电力电子、自动控制或电气工程等相关专业背景,熟悉MATLAB/Simulink仿真环境,正在从事新能源变换、电能质量治理、电机驱动或电力系统方向研究的研究生、高校教师及企业研发工程师。; 使用场景及目标:①开展三电平VIENNA整流器、双有源桥DAB、LLC谐振变换器等先进拓扑的科研建模与论文复现;②完成课程设计、毕业设计或实际工程项目中的控制器开发与系统性能验证;③深入掌握双闭环控制架构、中点电位平衡机制、SVPWM调制策略及系统稳定性分析等核心知识点; 阅读建议:建议结合Mathcad计算书进行系统参数设计,理解控制算法的数学基础,并在Simulink中逐步搭建与调试模型,注重理论计算与仿真结果的对比分析,推荐按照资源目录顺序循序渐进学习,以建立完整的知识框架和技术实现能力。

A股分钟行情数据,涵盖股票、ETF、可转债及指数 每条记录包含交易日期、具体时间、证券代码、证券简称、开盘价、最高价、最低价、收盘价、成交量、成交额 数据为日内分钟频率,逐分钟记录价格变动与成交信息

A股分钟行情数据,涵盖股票、ETF、可转债及指数。每条记录包含交易日期、具体时间、证券代码、证券简称、开盘价、最高价、最低价、收盘价、成交量、成交额。数据为日内分钟频率,逐分钟记录价格变动与成交信息,按交易日分割存储,历史分钟K线保留完整。 数据源:CMES金融数据库

上一篇: Beginning Auto Layout Tutorial in iOS 7: Part 2
下一篇: iOS应用性能调优的25个建议和技巧
WaveDHW
博客等级 码龄20年 455粉丝 159原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值