fixed broken links, added nifty mailto for 'Email Us' and finished adding preliminary code toggles

This commit is contained in:
Luke Parham
2016-04-19 16:13:11 -05:00
parent 1965dc0a82
commit 9aa4fbb9fa
5 changed files with 107 additions and 22 deletions

View File

@@ -39,7 +39,10 @@ Consider, the ASViewController subclass - LocationCollectionNodeController - fro
An `ASCollectionNode` is assigned to be managed by an `ASViewController` in its `initWithNode:` designated initializer method.
```objective-c
<div class = "highlight-group">
<span class="language-toggle"><a data-lang="swift" class="swiftButton">Swift</a><a data-lang="objective-c" class = "active objcButton">Objective-C</a></span>
<div class = "code">
<pre lang="objc" class="objcCode">
- (instancetype)initWithCoordinates:(CLLocationCoordinate2D)coordinates
{
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
@@ -53,7 +56,21 @@ An `ASCollectionNode` is assigned to be managed by an `ASViewController` in its
return self;
}
```
</pre>
<pre lang="swift" class = "swiftCode hidden">
func initWithCoordinates(coordinates: CLLocationsCoordinate2D) {
flowLayout = UICollectionViewFlowLayout()
collectionNode = ASCollectionNode(collectionViewLayout: flowLayout)
super.init(node: collectionNode)
flowLayout.minimumInteritemSpacing = 1
flowLayout.minimumLineSpacing = 1
}
</pre>
</div>
</div>
##Accessing the ASCollectionView##
If you've used previous versions of ASDK, you'll notice that `ASCollectionView` has been removed in favor of `ASCollectionNode`.
@@ -66,17 +83,33 @@ If you've used previous versions of ASDK, you'll notice that `ASCollectionView`
The LocationCollectionNodeController above accesses the ASCollectionView directly in viewDidLoad
```objective-c
- (void)loadView
<div class = "highlight-group">
<span class="language-toggle"><a data-lang="swift" class="swiftButton">Swift</a><a data-lang="objective-c" class = "active objcButton">Objective-C</a></span>
<div class = "code">
<pre lang="objc" class="objcCode">
- (void)viewDidLoad
{
[super loadView];
[super viewDidLoad];
_collectionNode.view.asyncDelegate = self;
_collectionNode.view.asyncDataSource = self;
_collectionNode.view.allowsSelection = NO;
_collectionNode.view.backgroundColor = [UIColor whiteColor];
}
```
</pre>
<pre lang="swift" class = "swiftCode hidden">
override func viewDidLoad() {
super.viewDidLoad()
collectionNode.view.asyncDelegate = self
collectionNode.view.asyncDataSource = self
collectionNode.view.allowsSelection = false
collectionNode.view.backgroundColor = UIColor.whiteColor()
}
</pre>
</div>
</div>
##Table Row Height##

View File

@@ -33,40 +33,78 @@ It is imperative that the data model be accessed outside of the node block. This
In the example below, you can see how the index is used to access the photo model before creating the node block.
```objective-c
<div class = "highlight-group">
<span class="language-toggle"><a data-lang="swift" class="swiftButton">Swift</a><a data-lang="objective-c" class = "active objcButton">Objective-C</a></span>
<div class = "code">
<pre lang="objc" class="objcCode">
- (ASCellNodeBlock)pagerNode:(ASPagerNode *)pagerNode nodeBlockAtIndex:(NSInteger)index
{
PhotoModel *photoModel = [_photoFeed objectAtIndex:index];
PhotoModel *photoModel = _photoFeed[index];
// this part can be executed on a background thread - it is important to make sure it is thread safe!
ASCellNode *(^ASCellNodeBlock)() = ^ASCellNode *() {
PhotoCellNode *cellNode = [[PhotoCellNode alloc] initWithPhotoObject:photoModel];
ASCellNode *(^cellNodeBlock)() = ^ASCellNode *() {
PhotoCellNode *cellNode = [[PhotoCellNode alloc] initWithPhoto:photoModel];
return cellNode;
};
return ASCellNodeBlock;
return cellNodeBlock;
}
```
</pre>
<pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeBlockAtIndex index: Int) -> ASCellNodeBlock! {
guard photoFeed.count > index else { return nil }
let photoModel = photoFeed[index]
let cellNodeBlock = { () -> ASCellNode in
let cellNode = PhotoCellNode(photo: photoModel)
return cellNode
}
return cellNodeBlock
}
</pre>
</div>
</div>
##Use ASViewControllers For Optimal Performance##
One especially useful pattern is to return an ASCellNode that is initialized with an existing UIViewController or ASViewController. For optimal performance, use an ASViewController.
```objective-c
<div class = "highlight-group">
<span class="language-toggle"><a data-lang="swift" class="swiftButton">Swift</a><a data-lang="objective-c" class = "active objcButton">Objective-C</a></span>
<div class = "code">
<pre lang="objc" class="objcCode">
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index
{
CGSize pagerNodeSize = pagerNode.bounds.size;
NSArray *animals = self.animals[index];
ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^{
return [[AnimalTableNodeController alloc] initWithAnimals:animals];;
} didLoadBlock:nil];
node.preferredFrameSize = pagerNodeSize;
node.preferredFrameSize = pagerNode.bounds.size;
return node;
}
```
</pre>
<pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeAtIndex index: Int) -> ASCellNode! {
guard animals.count > index else { return nil }
let animal = animals[index]
let node = ASCellNode(viewControllerBlock: { () -> UIViewController in
return AnimalTableNodeController(animals: animals)
}, didLoadBlock: nil)
node.preferredFrameSize = pagerNode.bounds.size
return node
}
</pre>
</div>
</div>
In this example, you can see that the node is constructed using the `-initWithViewControllerBlock:` method. It is usually necessary to provide a cell created this way with a preferredFrameSize so that it can be laid out correctly.
##Sample Apps##

View File

@@ -127,16 +127,31 @@ If you've used previous versions of ASDK, you'll notice that `ASTableView` has b
For example, you may want to set a table's separator style property. This can be done by accessing the table node's view in the `viewDidLoad:` method as seen in the example below.
```objective-c
<div class = "highlight-group">
<span class="language-toggle"><a data-lang="swift" class="swiftButton">Swift</a><a data-lang="objective-c" class = "active objcButton">Objective-C</a></span>
<div class = "code">
<pre lang="objc" class="objcCode">
- (void)viewDidLoad
{
[super viewDidLoad];
_tableNode.view.allowsSelection = NO;
_tableNode.view.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableNode.view.leadingScreensForBatching = AUTO_TAIL_LOADING_NUM_SCREENFULS; // overriding default of 2.0
_tableNode.view.leadingScreensForBatching = 3.0; // overriding default of 2.0
}
```
</pre>
<pre lang="swift" class = "swiftCode hidden">
override func viewDidLoad() {
super.viewDidLoad()
tableNode.view.allowsSelection = false
tableNode.view.separatorStyle = .None
tableNode.view.leadingScreensForBatching = 3.0 // overriding default of 2.0
}
</pre>
</div>
</div>
##Table Row Height##

View File

@@ -2,7 +2,7 @@
title: Layout Engine
layout: docs
permalink: /docs/layout-engine.html
next: asviewcontroller.html
next: containers-overview.html
---
AsyncDisplayKit's layout engine is based on the CSS Box Model. While it is the feature of the framework that bears the weakest resemblance to the UIKit equivalent (AutoLayout), it is also among the most useful features once you've gotten used to it. With enough practice, you may just come to prefer creating declarative layouts to the constraint based approach. ;]

View File

@@ -10,7 +10,6 @@ next: intelligent-preloading.html
For general discussion, announcements and help. Email AsyncDisplayKit@gmail.com for an invite.
###Learn more
- Read the <a href="/guide">Getting Started guide</a>
- Get the <a href="https://github.com/facebook/AsyncDisplayKit/tree/master/examples">sample projects</a>
- Browse the <a href="/appledocs.html">API reference</a>
- Watch the <a href="http://vimeo.com/103589245">NSLondon talk</a> or the <a href="https://www.youtube.com/watch?v=RY_X7l1g79Q">NSSpain talk</a>
@@ -20,4 +19,4 @@ For general discussion, announcements and help. Email AsyncDisplayKit@gmail.com
- <a href="https://itunes.apple.com/us/app/this-is-money/id768740884?mt=8">This is Money</a>
- and many more that we don't have permission to put here...
Email <a href="AsyncDisplayKit@gmail.com">us</a> to add your app to this list.
<a href="mailto:asyncdisplaykit@gmail.com?subject=An App for the Docs!">Email us</a> to add your app to this list.