mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-05-30 15:55:16 +08:00
Update containers-aspagernode.md
This commit is contained in:
@@ -5,7 +5,9 @@ permalink: /docs/containers-aspagernode.html
|
||||
next: display-node.html
|
||||
---
|
||||
|
||||
ASPagerNode is a subclass of ASCollectionNode. Using it allows you to produce a page style UI similar to what you'd create with UIKit's UIPageViewController. Luckily, the API is quite a bit simpler than UIPageViewController's.
|
||||
`ASPagerNode` is a subclass of `ASCollectionNode`.
|
||||
|
||||
Using it allows you to produce a page style UI similar to what you'd create with UIKit's `UIPageViewController`. ASPager node currently supports staying on the correct page during rotation. It does _not_ currently support circular scrolling.
|
||||
|
||||
The main dataSource methods are:
|
||||
|
||||
@@ -17,15 +19,15 @@ and
|
||||
|
||||
or
|
||||
|
||||
`- (ASCellNodeBlock)pagerNode:(ASPagerNode *)pagerNode nodeBlockAtIndex:(NSInteger)index` **(recommended)**
|
||||
`- (ASCellNodeBlock)pagerNode:(ASPagerNode *)pagerNode nodeBlockAtIndex:(NSInteger)index` **_(recommended)_**
|
||||
|
||||
These two methods, just as with `ASCollectionNode` and `ASTableNode` need to return either an `ASCellNode` or a block it can use to return one later.
|
||||
These two methods, just as with `ASCollectionNode` and `ASTableNode` need to return either an `ASCellNode` or an `ASCellNodeBlock` - a block that creates a `ASCellNode` which can be run on a background thread.
|
||||
|
||||
Note that `pagerNode:nodeAtIndex:` will be called on the main thread and should not implement reuse (it will be called once per row). Unlike UICollectionView's version, this method is not called when the row is about to display.
|
||||
Note that both of these methods should not implement reuse (they will be called once per row). Unlike UIKit, these methods are not called when the row is just about to display.
|
||||
|
||||
`pagerNode:nodeBlockAtIndex:` returns a block that creates the node for display at this index. This the reccommended option because it is more performant. It concurrently allocates cell nodes, meaning that all of the `init:` methods for all of your subnodes are run in the background. It is very important to note that blocks **must be thread-safe** as they can be called on the main thread or a background queue. They should also not implement reuse (it will be called once per row).
|
||||
While `pagerNode:nodeAtIndex:` will be called on the main thread, `pagerNode:nodeBlockAtIndex:` is preferred because it concurrently allocates cell nodes, meaning that all of the `init:` methods for all of your subnodes are run in the background. **It is very important that node blocks be thread-safe** as they can be called on the main thread or a background queue.
|
||||
|
||||
##nodeBlockAtIndex: Thread Safety Warning & Example##
|
||||
##Node Block Thread Safety Warning##
|
||||
|
||||
It is imperative that the data model be accessed outside of the node block. This means that it is highly unlikely that you should need to use the index inside of the block.
|
||||
|
||||
@@ -46,9 +48,9 @@ In the example below, you can see how the index is used to access the photo mode
|
||||
}
|
||||
```
|
||||
|
||||
##nodeAtIndex: Example##
|
||||
##Use ASViewControllers For Optimal Performance##
|
||||
|
||||
One especially useful pattern is to return an ASCellNode that is initialized with an existing UIViewController or ASViewController.
|
||||
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
|
||||
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index
|
||||
@@ -67,9 +69,10 @@ One especially useful pattern is to return an ASCellNode that is initialized wit
|
||||
```
|
||||
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##
|
||||
|
||||
Check out the following sample apps to see an ASPagerNode implemented within an app:
|
||||
<ul>
|
||||
<li><a href="https://github.com/facebook/AsyncDisplayKit/tree/master/examples/PagerNode">PagerNode</a></li>
|
||||
<li><a href="https://github.com/facebook/AsyncDisplayKit/tree/master/examples/VerticalWithinHorizontalScrolling">VerticalWithinHorizontalScrolling</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user