mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-05-13 09:16:39 +08:00
Update README.md
This commit is contained in:
104
README.md
104
README.md
@@ -1,7 +1,7 @@
|
||||

|
||||
|
||||
[](http://cocoapods.org/pods/AsyncDisplayKit)
|
||||
[](http://cocoapods.org/pods/AsyncDisplayKit)
|
||||
[](http://cocoapods.org/pods/AsyncDisplayKit)
|
||||
[](http://cocoapods.org/pods/AsyncDisplayKit)
|
||||
|
||||
[](http://AsyncDisplayKit.org)
|
||||
[](http://AsyncDisplayKit.org)
|
||||
@@ -11,113 +11,35 @@
|
||||
[](https://travis-ci.org/facebook/AsyncDisplayKit)
|
||||
[](https://github.com/facebook/AsyncDisplayKit/blob/master/LICENSE)
|
||||
|
||||
## Installation
|
||||
|
||||
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](https://facebook.com/paper) possible, and goes hand-in-hand with
|
||||
[pop](https://github.com/facebook/pop)'s physics-based animations — but
|
||||
it's just as powerful with UIKit Dynamics and conventional app designs.
|
||||
ASDK is available via CocoaPods or Carthage. See our [Installation](http://asyncdisplaykit.org/docs/installation.html) guide for instructions.
|
||||
|
||||
### Quick start
|
||||
## Performance Gains
|
||||
|
||||
ASDK is available on [CocoaPods](http://cocoapods.org). Add the following to your Podfile:
|
||||
AsyncDisplayKit's basic unit is the `node`. An ASDisplayNode is an abstraction over `UIView`, which in turn is an abstraction over `CALayer`. Unlike views, which can only be used on the main thread, nodes are thread-safe: you can instantiate and configure entire hierarchies of them in parallel on background threads.
|
||||
|
||||
```ruby
|
||||
pod 'AsyncDisplayKit'
|
||||
```
|
||||
|
||||
(ASDK can also be used as a regular static library: Copy the project to your
|
||||
codebase manually, adding `AsyncDisplayKit.xcodeproj` to your workspace. Add
|
||||
`libAsyncDisplayKit.a`, MapKit, AssetsLibrary, and Photos to the "Link Binary With
|
||||
Libraries" build phase. Include `-lc++ -ObjC` in your project linker flags.)
|
||||
To keep its user interface smooth and responsive, your app should render at 60 frames per second — the gold standard on iOS. This means the main thread has one-sixtieth of a second to push each frame. That's 16 milliseconds to execute all layout and drawing code! And because of system overhead, your code usually has less than ten milliseconds to run before it causes a frame drop.
|
||||
|
||||
Import the framework header, or create an [Objective-C bridging
|
||||
header](https://developer.apple.com/library/ios/documentation/swift/conceptual/buildingcocoaapps/MixandMatch.html)
|
||||
if you're using Swift:
|
||||
AsyncDisplayKit lets you move image decoding, text sizing and rendering, layout, and other expensive UI operations off the main thread, to keep the main thread available to respond to user interaction.
|
||||
|
||||
```objective-c
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
```
|
||||
## Advanced Developer Features
|
||||
|
||||
AsyncDisplayKit Nodes are a thread-safe abstraction layer over UIViews and
|
||||
CALayers:
|
||||
|
||||

|
||||
## Learn More
|
||||
|
||||
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:
|
||||
|
||||
```objective-c
|
||||
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_async(dispatch_get_main_queue(), ^{
|
||||
[self.view addSubview:node.view];
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
In Swift:
|
||||
|
||||
```swift
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) {
|
||||
let node = ASTextNode()
|
||||
node.attributedString = NSAttributedString(string: "hello")
|
||||
node.measure(CGSize(width: screenWidth, height: CGFloat.max))
|
||||
node.frame = CGRect(origin: CGPointZero, size: node.calculatedSize)
|
||||
|
||||
// self.view isn't a node, so we can only use it on the main thread
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
self.view.addSubview(node.view)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
AsyncDisplayKit at a glance:
|
||||
|
||||
* `ASImageNode` and `ASTextNode` are drop-in replacements for UIImageView and
|
||||
UITextView.
|
||||
* `ASMultiplexImageNode` can load and display progressively higher-quality
|
||||
variants of an image over a slow cell network, letting you quickly show a
|
||||
low-resolution photo while the full size downloads.
|
||||
* `ASNetworkImageNode` is a simpler, single-image counterpart to the Multiplex
|
||||
node.
|
||||
* `ASTableView` and `ASCollectionView` are a node-aware UITableView and
|
||||
UICollectionView, respectively, that can asynchronously preload cell nodes
|
||||
— from loading network data to rendering — all without blocking
|
||||
the main thread.
|
||||
|
||||
You can also easily [create your own
|
||||
nodes](https://github.com/facebook/AsyncDisplayKit/blob/master/AsyncDisplayKit/ASDisplayNode%2BSubclasses.h)
|
||||
to implement node hierarchies or custom drawing.
|
||||
|
||||
## Learn more
|
||||
|
||||
* Read the [Getting Started guide](http://asyncdisplaykit.org/docs/getting-started.html)
|
||||
* Read the our [Getting Started guide](http://asyncdisplaykit.org/docs/getting-started.html)
|
||||
* Get the [sample projects](https://github.com/facebook/AsyncDisplayKit/tree/master/examples)
|
||||
* Browse the [API reference](http://asyncdisplaykit.org/appledocs.html)
|
||||
* Watch the [NSLondon talk](http://vimeo.com/103589245) or the [NSSpain talk](https://www.youtube.com/watch?v=RY_X7l1g79Q)
|
||||
|
||||
## Getting Help
|
||||
|
||||
We use Slack for real-time debugging, community updates, and general talk about ASDK. Signup at http://asdk-slack-auto-invite.herokuapp.com or email AsyncDisplayKit(at)gmail.com to get an invite.
|
||||
|
||||
## Testing
|
||||
|
||||
AsyncDisplayKit has extensive unit test coverage. You'll need to run `pod install` in the root AsyncDisplayKit directory to set up OCMock.
|
||||
|
||||
## Contributing
|
||||
|
||||
See the CONTRIBUTING file for how to help out.
|
||||
We welcome any contributions. See the [CONTRIBUTING file](https://github.com/facebook/AsyncDisplayKit/blob/master/CONTRIBUTING.md) for how to get involved.
|
||||
|
||||
## License
|
||||
|
||||
AsyncDisplayKit is BSD-licensed. We also provide an additional patent grant.
|
||||
|
||||
The files in the /examples directory are licensed under a separate license as specified in each file; documentation is licensed CC-BY-4.0.
|
||||
AsyncDisplayKit is BSD-licensed. We also provide an additional patent grant. The files in the `/examples` directory are licensed under a separate license as specified in each file; documentation is licensed CC-BY-4.0.
|
||||
|
||||
Reference in New Issue
Block a user