在我的代码中,调用layoutAttributesForElementsInRect,但是layoutAttributesForItemAtIndexPath不是.什么决定哪个被叫? layoutAttributesForItemAtIndexPath在哪里被调用?
解决方法 layoutAttributesForElementsInRect:不一定调用layoutAttributesForItemAtIndexPath :.实际上,如果你的UICollectionVIEwFlowLayout子类化,流布局将准备布局并缓存生成的属性.所以当layoutAttributesForElementsInRect:被调用时,它不会要求layoutAttributesForItemAtIndexPath:,而只是使用缓存的值.
如果要确保布局属性总是根据布局进行修改,请为layoutAttributesForElementsInRect:和layoutAttributesForItemAtIndexPath ::实现一个修饰符
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{ NSArray *attributesInRect = [super layoutAttributesForElementsInRect:rect]; for (UICollectionVIEwLayoutAttributes *cellAttributes in attributesInRect) { [self modifyLayoutAttributes:cellAttributes]; } return attributesInRect;}- (UICollectionVIEwLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath{ UICollectionVIEwLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath]; [self modifyLayoutAttributes:attributes]; return attributes;}- (voID)modifyLayoutAttributes:(UICollectionVIEwLayoutAttributes *)attributes{ // Adjust the standard propertIEs size,center,transform etc. // Or subclass UICollectionVIEwLayoutAttributes and add additional attributes. // Note,that a subclass will require you to overrIDe copyWithZone and isEqual. // And you'll need to tell your layout to use your subclass in +(Class)layoutAttributesClass}总结
以上是内存溢出为你收集整理的ios – UICollectionViewLayout layoutAttributesForElementsInRect和layoutAttributesForItemAtIndexPath全部内容,希望文章能够帮你解决ios – UICollectionViewLayout layoutAttributesForElementsInRect和layoutAttributesForItemAtIndexPath所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)