版本 0.0.4 的 ZCAnimatedLabel

ZCAnimatedLabel 0.0.4

测试测试过
语言语言 Obj-CObjective C
许可证 MIT
发布最后一次发布2016年1月

Chen Zhang 维护。



  • 作者:
  • Chen Zhang

类似于 UILabel 的视图,具有易于扩展的显示/隐藏动画

特性

  • 支持富文本(使用 NSAttributedString)
  • 支持按字符/单词/行分组动画
  • 每个文本块的动画开始延迟可自定义
  • 性能出色,只有更改区域会被重绘
  • 可选基于层的实现
  • 3D/几何变换支持(仅基于层)
  • iOS 5+ 兼容性

演示

  • 默认

image

image

  • Duang/Spring

image

  • Flyin

image

  • Focus

image

  • Shapeshift

image

  • Reveal

image

  • Thrown

    image

  • Transparency

image

  • Spin

image

  • Dash

image

  • 未来还有更多

如何使用

ZCAnimatedLabel 通过 CocoaPods 提供。如果你不需要所有的效果子类,只需将 ZCAnimatedLabel.(h|m)ZCCoreTextLayout.(h|m)ZCEasingUtil.(h|m) 拖入你的项目中,并开始自定义。

子类化

ZCAnimatedLabel 有两种模式:非层和基于层。在第一种模式中,ZCAnimatedLabel 是一个平面的 UIView,每个动画阶段都是使用 Core Graphics 绘制的,你可以自定义重绘区域以获得更佳的性能。以下方法可以被覆盖:

  • - (void) textBlockAttributesInit: (ZCTextBlock *) textBlock;
  • - (void) appearStateDrawingForRect: (CGRect) rect textBlock: (ZCTextBlock *) textBlock;
  • - (void) disappearStateDrawingForRect: (CGRect) rect textBlock: (ZCTextBlock *) textBlock;
  • - (CGRect) redrawAreaForRect: (CGRect) rect textBlock: (ZCTextBlock *) textBlock;

第二种选项是基于层,其中每个文本块都是一个简单的 CALayer,通过设置层的 transform 属性,可以在这种模式中实现 3D 转换,如果在重绘区域大且文本块不多的情况下,可以实现性能提升。设置 self.layerBasedYES 并覆盖以下方法进行自定义:

  • - (void) textBlockAttributesInit: (ZCTextBlock *) textBlock;
  • - (void) appearStateLayerChangesForTextBlock: (ZCTextBlock *) textBlock;
  • - (void) disappearLayerStateChangesForTextBlock: (ZCTextBlock *) textBlock;

待办事项

  • 将不再进行动画的 CALayers 合并到一个单一代理存储中,并重用CALayer来动画层。 (对基于层的实现有更好的性能)
  • 更多效果,可能是与位图相关的效果
  • 使用核心动画发射器

感谢

  • LTMorhpingLabel 提供了重要的灵感。如果你喜欢 ZCAnimatedLabel,你绝对应该试试这个。
  • AGGeometryKit 是在 ZCDashLabel 中使用的任意形状 3D 变换代码片段。