UICollectionViewFlowLayout *yLayout = [[UICollectionViewFlowLayout alloc] init]; yLayout.sectionHeadersPinToVisibleBounds = YES; yLayout.sectionFootersPinToVisibleBounds = YES; //return YES;表示一旦滑动就实时调用上面这个layoutAttributesForElementsInRect:方法 - (BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBound { return YES; }