BBCyclingLabel

BBCyclingLabel is just like a UILabel but allows you to perform custom animations when changing text.

Instead of using two UILabel's and cross fading them, you can use this component and configure it to crossfade; it'll then take care of performing the cross fade for you.

Here's a demo video of this component running on the demo project BBCyclingLabelDemo.

BBCyclingLabel很像一个UILabel,但是允许你在修改文本的时候执行动画切换效果。

你不需要用两个label叠加隐藏的方式来实现变色动画,使用这个组件就行了,改变文本就会触发动画,就是这么简单。

How it works

Under the hood, BBCyclingLabel simply animates transitions between two UILabels, which are always cycled when changing text.

BBCyclingLabel简单的使用了两个label的转场动画,在你改变文本的时候就能触发动画效果。

How to use it

CGRect labelFrame = ...;

BBCyclingLabel* label = [[BBCyclingLabel alloc] initWithFrame:labelFrame];
label.transitionEffect = BBCyclingLabelTransitionEffectCrossFade;
label.transitionDuration = 0.3;
// Initial text doesn't need to be animated so we explicitly call a method to bypass it
[label setText:@"Initial text" animated:NO]; // ... // Using the property 'text', the component will always animate
label.text = @"This will cross fade with initial text"

Component properties

Apart from all the properties present in a UILabelBBCyclingLabel has four more properties:

除了UILabel的一些属性外,BBCyclingLabel额外提供了4个属性:

BBCyclingLabelTransitionEffect   transitionEffect;
NSTimeInterval transitionDuration;
BBCyclingLabelPreTransitionBlock preTransitionBlock;
BBCyclingLabelTransitionBlock transitionBlock;
  • transitionEffect: A value of the enum BBCyclingLabelTransitionEffect that determines which animation effect will be used to cycle text. 转场效果
  • transitionDuration: Duration, in milliseconds, for the transition animation; 转场时间
  • preTransitionBlock and transitionBlock: Blocks to be executed before and during the transition -- should only be manually set when performing custom effects. 转场动画的block

Effects

This component supports the following simple effects:

这个组件支持以下多种简单的效果:

  • Fade in (BBCyclingLabelTransitionEffectFadeIn)
  • Fade out (BBCyclingLabelTransitionEffectFadeOut)
  • Zoom in (increase scale, BBCyclingLabelTransitionEffectZoomIn)
  • Zoom out (reduce scale, BBCyclingLabelTransitionEffectZoomOut)
  • Scroll up (BBCyclingLabelTransitionEffectScrollUp)
  • Scroll down (BBCyclingLabelTransitionEffectScrollDown)

It also offers the following composite effects (combinations of the above):

他也提供一下的一些混合的效果(上面效果的组合):

  • Cross fade (fade out + fade in, BBCyclingLabelTransitionEffectCrossFade)
  • Scaled fade out (fade out + fade in + zoom out, BBCyclingLabelTransitionEffectScaleFadeOut)
  • Scaled fade in (fade out + fade in + zoom in, BBCyclingLabelTransitionEffectScaleFadeIn)

Predefined effects can be combined using the logic OR operator. If you want to make the current text fade out while scrolling both current and new up, you can do this by combining the fade out and scroll up effects:

预定义效果可以通过或操作来实现。

BBCyclingLabelTransitionEffect effect = BBCyclingLabelTransitionEffectFadeOut |
BBCyclingLabelTransitionEffectScrollUp;

If you want to perform a cross fade with a scroll up, you can either do it in one of the following two ways:

如果你想执行交叉渐变上滑效果,你可以通过以下两种方式来实现:

BBCyclingLabelTransitionEffect effect = BBCyclingLabelTransitionEffectFadeOut |
BBCyclingLabelTransitionEffectFadeIn |
BBCyclingLabelTransitionEffectScrollUp; BBCyclingLabelTransitionEffect effect = BBCyclingLabelTransitionEffectCrossFade |
BBCyclingLabelTransitionEffectScrollUp;

Customizable effects

If the predefined effects are not enough, you can get your hands dirty and roll in your own custom transitions. To do that, you need to set the transitionEffect property toBBCyclingLabelTransitionEffectCustom and assign blocks to preTransitionBlock andt ransitionBlock.

如果预定义效果满足不了你的需求,你可以装逼自己来,你需要给toBBCyclingLabelTransitionEffectCustom赋值并给preTransitionBlock与ransitionBlock赋值。

The preTransitionBlock block has the following signature:

preTransitionBlock这个block有着如下的内容:

^(UILabel* labelToEnter)

This block is called right before the transition begins so you can prepare the new label (the label that's about to replace the current text) to enter. This is where you should reset the state of the entering label.

在转场动画开始的时候,这个block就会被调用,这时候你需要重设他:

The transitionBlock block has the following signature:

^(UILabel* labelToExit, UILabel* labelToEnter)

This block will be called with both labels, the one that's about to be replaced and the one with the new text. This is where you perform the transition itself. Hide, rotate, fade, scale, etc, this is where you go wild on the effects; just make sure you leave things in a usable state.

这个block会被两个label分开调用。

Here's a silly example that performs a 180º rotation + scale down to 0.2 on the exiting label and simply fades in the entering label:

// Never forget to set this to custom
_customLabel.transitionEffect = BBCyclingLabelTransitionEffectCustom;
_customLabel.preTransitionBlock = ^(UILabel* labelToEnter) {
// Reset the label to enter; make sure it's at alpha 0 and has no transforms applied to it
labelToEnter.transform = CGAffineTransformIdentity;
labelToEnter.alpha = 0;
};
_customLabel.transitionBlock = ^(UILabel* labelToExit, UILabel* labelToEnter) {
// Fade the exiting label out...
labelToExit.alpha = 0;
// ... and apply a rotation + scale transform
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
labelToExit.transform = CGAffineTransformScale(transform, 0.2, 0.2);
// Fade the entering label in
labelToEnter.alpha = 1;
};

[翻译] BBCyclingLabel的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. 四大组件之Service

    1 通过startService 1.1 与调用者相对独立,没有返回,用于播放音乐,下载文件 1.2 如果是调用者自己直接退出而没有调用stopService的话,Service会一直在后台运行.下次 ...

  2. Android开源项目xUtils HttpUtils模块分析(转)

    xUtils是github上的一个Android开源工具项目,其中HttpUtils模块是处理网络连接部分,刚好最近想整理下Android网络编程知识,今天学习下xUtils中HttpUtils. x ...

  3. MapReduce原理——分而治之

    一.MapReduce简介 二.MapReduce并行处理的基本过程 三.MapReduce实际处理流程 四.一个job的运行流程 一.MapReduce简介 MapReduce是一种并行可扩展计算模 ...

  4. PTA (Advanced Level) 1022 Digital Library

    Digital Library A Digital Library contains millions of books, stored according to their titles, auth ...

  5. ansible 回调函数处理

    https://www.u3v3.com/ar/1421 https://serversforhackers.com/c/running-ansible-2-programmatically

  6. SQL Serever学习14——存储过程和触发器

    存储过程 在数据库中很多查询都是大同小异,编写他们费时费力,将他们保存起来,以后执行就很方便了,把SQL语句“封装”起来. 存储过程的概念 存储过程是一组SQL语句集,经过编译存储,可以”一次编译,多 ...

  7. Python——第一个python程序helloworld

    安装了Python的环境之后,就是编写Python的代码了. 首先,我们来写一个简单的“hello world” 新建一个空白的txt文本,将后缀改为.py 改了后缀之后即变为Python程序的图标 ...

  8. ssh 远程拷贝文件到本地

     scp userA@192.168.0.205:/home/xinshang-toolkit/wwwroot/macheng/tianxiaohuanew-mc.dsceshi.cn/public/ ...

  9. Office 卸载问题(安装包的语言不受系统支持)

    本人系统Win7 这个问题搞了一下午.各种网站找解决办法.下载下来的都是一些垃圾软件. Win7以上调成兼容模式运行理论可行. 放上微软的解决方法: * 彻底卸载Office 2003: http:/ ...

  10. Docker学习(二): 镜像的使用与构建

    特别声明: 博文主要是学习过程中的知识整理,以便之后的查阅回顾.部分内容来源于网络(如有摘录未标注请指出).内容如有差错,也欢迎指正! =============系列文章============= 1 ...