码迷,mamicode.com
首页 > 其他好文 > 详细

[翻译] AsyncDisplayKit

时间:2014-10-18 22:17:45      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   使用   

AsyncDisplayKit

bubuko.com,布布扣

bubuko.com,布布扣

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

bubuko.com,布布扣

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

 

[翻译] AsyncDisplayKit

标签:des   style   blog   http   color   io   os   ar   使用   

原文地址:http://www.cnblogs.com/YouXianMing/p/4033705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!