I did not find an API that returns the constrainedSize of the header.
extension ViewController: ASCollectionDelegate, UICollectionViewDelegateFlowLayout {
func collectionNode(_ collectionNode: ASCollectionNode, constrainedSizeForItemAt indexPath: IndexPath) -> ASSizeRange {
return ASSizeRange(
min: CGSize(width: collectionNode.frame.width, height: 0),
max: CGSize(width: collectionNode.frame.width, height: .infinity)
)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
// 馃敟 I want to return the value so that it becomes the size of CellNode itself here
return CGSize(width: collectionView.frame.width, height: 40)
}
}
would you mind to clarify your question? what do you want to achieve ?
@hashemp206
Cell can decide the size based on constrainedSize, but I do not know how to realize it with Header.
the simplest solution is add another section with only one cell that act as the header.
@hashemp206
Thank you very much.
That way is certainly possible.
However, I would like to know if there is a way to realize it with SectionHeader.
@muukii Hi! If you set UICollectionViewFlowLayout.headerReferenceSize or implement - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
then ASDK will treat the reference size as a maximum size and measure the header with constrained size range: {{0, 0}, {cv.width, headerReferenceSize}} (for a vertical flow). Does that make sense?
@Adlai-Holler
Currently it is implemented as follows.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
// TODO: Self-sizing
return CGSize(width: collectionView.frame.width, height: 60)
}
}
The UI looks like this.

Header is self-sizing but ReusableView does not seem to be able to fit the size of Header.
@Adlai-Holler
I am reading the ASDK code.
HeaderReferenceSize is used only as max and UICollectionReusableView is not scaled down according to ASCellNode, right?
馃憖
+1
Is it possible to make supplementary views size themselves or not?
EDIT
My apologies. This seems to be an issue in 1.9.x. Supplementary nodes resize fine in at least 2.1
I've created a sample that has working self-sizing supplementary nodes.
https://github.com/ImJCabus/ASCollectionNodeAutoHeader
So the answer is: Yes, it's certainly possible to employ self-sizing headers.
@hannahmbanana @appleguy
Maybe close this issue?
Hey @muukii it seems @ImJCabus and others in this thread answered your questions. I will close this issue for now. Thanks!
For further questions please join our Slack channel: http://asyncdisplaykit.org/slack.html
Oh Thanks. I'll check it
Most helpful comment
the simplest solution is add another section with only one cell that act as the header.