diff --git a/_docs/cell-node.md b/_docs/cell-node.md index 74c65e53..6faa4a08 100755 --- a/_docs/cell-node.md +++ b/_docs/cell-node.md @@ -7,4 +7,7 @@ next: text-cell-node.html ASCellNode is maybe the most commonly subclassed node. It can be used as the cell for both ASTableNodes and ASCollectionNodes. -If you don't feel like subclassing you're also free to use the `-initWithView:` or `initWithViewController:` methods to return nodes with backing views created from an existing view or view controller you already have. \ No newline at end of file +That being said, subclassing it is largely the same as subclassing a regular ASDisplayNode. Most importantly, you'll write an -init method, a -layoutSpecThatFits: method for measurement and layout, and, if necessary, a -didLoad method for adding extra gesture recognizers and a -layout method for any extra layout needs. + +If you don't feel like subclassing you're also free to use the `-initWithView:` or `-initWithViewController:` methods to return nodes with backing views created from an existing view or view controller you already have. + diff --git a/_docs/containers-ascollectionnode.md b/_docs/containers-ascollectionnode.md index 72671ae7..40e92fe9 100755 --- a/_docs/containers-ascollectionnode.md +++ b/_docs/containers-ascollectionnode.md @@ -5,39 +5,77 @@ permalink: /docs/containers-ascollectionnode.html next: containers-aspagernode.html --- -`ASCollectionNode` is equivalent to UIKit's `UICollectionView` and can be used in place of any UICollectionView. +ASCollectionNode is equivalent to UIKit's UICollectionView and can be used in place of any UICollectionView. ASCollectionNode replaces UICollectionView's required method -`collectionView:cellForItemAtIndexPath:` +
+ + Swift + Objective-C + + +
+
+- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
+  
+ + +
+
with your choice of **_one_** of the following methods -`- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath` +
+SwiftObjective-C -or - -`- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath` **_(recommended)_** - -
-Note that these are the same methods as the `ASTableNode`! Please read the previous `ASTableNode` section as most of the details here are identical and so we will gloss over them quickly. +
+
+- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
+
+ +
-As noted in the previous section +

+or +

+ +
+SwiftObjective-C + +
+
+- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
+
+ +
+
+ +It is recommended that you use the node block version of the method so that your collection node will be able to prepare and display all of its cells concurrently. + +As noted in the previous section: + -##Replace UICollectionViewController with ASViewController## +### Replacing a UICollectionViewController with an ASViewController -AsyncDisplayKit does not offer an equivalent to UICollectionViewController. Instead, you can use the flexibility of ASViewController to recreate any type of UIViewController. +AsyncDisplayKit does not offer an equivalent to UICollectionViewController. Instead, you can use the flexibility of ASViewController to recreate any type of UI...ViewController. Consider, the following ASViewController subclass. -An `ASCollectionNode` is assigned to be managed by an `ASViewController` in its `initWithNode:` designated initializer method, thus making it a sort of ASCollectionNodeController. +An ASCollectionNode is assigned to be managed by an `ASViewController` in its `-initWithNode:` designated initializer method, thus making it a sort of ASCollectionNodeController.
SwiftObjective-C @@ -72,16 +110,16 @@ init() {
-This works just as well with any node such as an ASTableNode, ASPagerNode, etc. +This works just as well with any node including as an ASTableNode, ASPagerNode, etc. -##Accessing the ASCollectionView## +### Accessing the ASCollectionView If you've used previous versions of ASDK, you'll notice that `ASCollectionView` has been removed in favor of `ASCollectionNode`.
-`ASCollectionView` (an actual UICollectionView subclass) is still used as an internal property of `ASCollectionNode`. While it should not be created directly, it can still be used directly by accessing the .view property of an `ASCollectionNode`. -
+ASCollectionView, an actual UICollectionView subclass, is still used internally by ASCollectionNode. While it should not be created directly, it can still be used directly by accessing the .view property of an ASCollectionNode. -
Do not forget that anything that accesses a view using AsyncDisplayKit's node containers or nodes should be done in viewDidLoad or didLoad, respectively.
+Don't forget that a node's view or layer property should only be accessed after viewDidLoad or didLoad, respectively, have been called. + The LocationCollectionNodeController above accesses the ASCollectionView directly in viewDidLoad @@ -113,17 +151,20 @@ override func viewDidLoad() { -##Table Row Height## +### Cell Sizing and Layout -As discussed in the previous `ASTableNode` section, ASCollectionNodes and ASTableNodes do not need to keep track of the height of their ASCellNodes. +As discussed in the previous section, ASCollectionNodes and ASTableNodes do not need to keep track of the height of their ASCellNodes. -***constrainedSizeForNode (also in table, but more important for collection) - - check that (0,0) min and (infinity, infinity) max -- example sample photo grid - - popover, rotated -> how to get size constraint (USE constrainedSizeForNode to do simple divide by 3 width thing) -- document itemSize (check what happens in ASDKgram) +Right now, cells will grow to fit their constrained size and will be laid out by whatever UICollectionViewLayout you provide. + +Soon, there will be a method such as ASTableNode's `-constrainedSizeForRow:` but at the moment, if you'd like to constrain the size of a cell used in a collection node, you need to wrap your layoutSpec object in an `ASStaticLayoutSpec` and provide it with a + +### Examples + +The most detailed example of laying out the cells of an ASCollectionNode is the CustomCollectionView app. It includes a Pinterest style cell layout using an ASCollectionNode and a custom `UICollectionViewLayout`. + +#### More Sample Apps with ASCollectionNodes -##Sample Apps with ASCollectionNodes##