openboy2012 / ddcollectionviewflowlayout Goto Github PK
View Code? Open in Web Editor NEWa CollectionViewFlowLayout implement the Waterfall Effect and support mutiple section
Home Page: http://dwz.cn/IRTpt
a CollectionViewFlowLayout implement the Waterfall Effect and support mutiple section
Home Page: http://dwz.cn/IRTpt
collectionView 采用datasource 设置 section 数量,那么 self.collectionView.numberOfSections 总是 0,导致后面数组越界引起crash
系统的 Layout 的Delegate是取的 CollectionView.delegate。例如 UICollectionViewFlowLayout 的 delegate 是 UICollectionViewDelegateFlowLayout,并未单独设置 UICollectionViewFlowLayout.delegate ,而是直接用 collectionView.delegate 即可。
Layout 可以设置默认属性,例如 minimumLineSpacing ,minimumInteritemSpacing,sectionInset 这些可以不通过 delegate 来设置。目前貌似无效。
在使用系统的 FlowLayout 的时候,有实现 header 和 footer 的相关回调:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
if (section == 0) {
return CGSizeZero;
} else { return CGSizeMake(320, 10); }
}
系统判断,如果高度为0,不会调用 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
.
目前的 DDCollectionViewLayout 在 - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
中,没有判断 height 为 0 的情况:
// Check footer layout attributes's rectangles if intersectes the collectionView's rectangles.
if ([self.headerFooterItemAttributes[UICollectionElementKindSectionFooter] count] > sectionIdx) {
UICollectionViewLayoutAttributes *footerAttribute = self.headerFooterItemAttributes[UICollectionElementKindSectionFooter][sectionIdx];
BOOL isVisible = CGRectIntersectsRect(rect, footerAttribute.frame);
if (isVisible && footerAttribute)
[itemAttrs addObject:footerAttribute];
self.currentEdgeInsets = UIEdgeInsetsZero;
} else {
self.currentEdgeInsets = [self.sectionInsetses[sectionIdx] UIEdgeInsetsValue];
}
应该修改为
if (isVisible && footerAttribute && footerAttribute.frame.size.height > 0)
header 同理。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.