zum*_*zum 9 ios uicollectionview
我正在为UICollectionView编写自定义流布局.我可以看到并滚动细胞.
问题是我无法显示节标题的补充视图.
所以,
- (UICollectionViewLayoutAttributes *)
layoutAttributesForSupplementaryViewOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
永远不会被召唤.
在数据源中这种方法:
- (UICollectionReusableView *)
collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
也永远不会被召唤.
我怎样才能这样调用这些方法呢?
编辑:这是layoutAttributesForElementsInRect:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray * attributes = [NSMutableArray arrayWithCapacity:[[self.layoutInfo allKeys] count]];
for(NSIndexPath * indexPath in self.layoutInfo) {
UICollectionViewLayoutAttributes *itemAttributes = [self.layoutInfo objectForKey:indexPath];
if(CGRectIntersectsRect(rect, itemAttributes.frame)) {
[attributes addObject:itemAttributes];
}
}
return attributes;
}
Run Code Online (Sandbox Code Playgroud)
因此即使这样,也不会调用补充视图的两种方法.
rob*_*off 11
您需要实现layoutAttributesForElementsInRect:为每个补充视图(除了每个单元格)返回一个属性实例:
子类必须覆盖此方法,并使用它返回视图与指定矩形相交的所有项的布局信息.您的实现应返回所有可视元素的属性,包括单元格,补充视图和装饰视图.
| 归档时间: |
|
| 查看次数: |
4730 次 |
| 最近记录: |