首页 > 代码库 > [翻译] AsyncDisplayKit

[翻译] AsyncDisplayKit

AsyncDisplayKit

AsyncDisplayKit is an iOS framework that keeps even the most complex user interfaces smooth and responsive. It was originally built to make Facebook‘s Paper possible, and goes hand-in-hand with pop‘s physics-based animations — but it‘s just as powerful with UIKit Dynamics and conventional app designs.

 AsyncDisplayKit(异步图形显示)是一个iOS的开源框架,它能改善非常复杂的用户交互卡顿的问题,并使其圆滑。最开始,开发它是用来优化Facebook的Paper应用,以及配合pop的物理引擎动画--当然,它像UIKit Dynamics框架一样高效且设计精美。

Quick start

ASDK is available on CocoaPods. Add the following to your Podfile:

ASDK可以通过CocoaPods安装,添加以下文件到Podfile中:

pod ‘AsyncDisplayKit‘

Import the framework header, or create an Objective-C bridging header if you‘re using Swift:

导入框架的头文件,或者创建Objective-C bridging header,如果你是使用Swift开发:

#import <AsyncDisplayKit/AsyncDisplayKit.h>

AsyncDisplayKit Nodes are a thread-safe abstraction layer over UIViews and CALayers:

AsyncDisplayKit的节点是一个线程安全的抽象layer,覆盖了UIView以及CALayer

You can construct entire node hierarchies in parallel, or instantiate and size a single node on a background thread — for example, you could do something like this in a UIViewController:

你可以通过封装的方式,或者是直接在子线程中实例化一个节点对象 -- 例如,你可以在UIViewController中做如下的操作:

dispatch_async(_backgroundQueue, ^{  ASTextNode *node = [[ASTextNode alloc] init];  node.attributedString = [[NSAttributedString alloc] initWithString:@"hello!"                                                          attributes:nil];  [node measure:CGSizeMake(screenWidth, FLT_MAX)];  node.frame = (CGRect){ CGPointZero, node.calculatedSize };  // self.view isn‘t a node, so we can only use it on the main thread  dispatch_sync(dispatch_get_main_queue(), ^{    [self.view addSubview:node.view];  });});

You can use ASImageNode and ASTextNode as drop-in replacements for UIImageView and UITextView, or create your own nodes to implement node hierarchies or custom drawing. ASTableView is a node-aware UITableView subclass that can asynchronously preload cell nodes without blocking the main thread.

你可以使用ASImageNode以及ASTextNode的继承类来替换UIImageView以及UITextView,或者创建你自己的节点,用以实现你自己的绘制方式,ASTableView就是一个自定义node的UITableView的子类,它可以异步装载cell节点而不阻塞主线程。

 

Learn more

  • Read the Getting Started guide
  • Get the sample projects
  • Browse the API reference
  • Watch the NSLondon talk

 

[翻译] AsyncDisplayKit