|
第一种方法
The best way to achieve this is to make a section header for the first section. Then set the UICollectionViewFlowLayout's property:
@property(nonatomic) BOOL sectionHeadersPinToVisibleBounds
or swift
var sectionHeadersPinToVisibleBounds: Bool
to NO (false for swift). This will ensure that the section header scrolls continuously with the cells and does not get pinned to the top like a section header normally would.
第二种方法
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height) collectionViewLayout:flowlayout];
self.collectionView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);
UIImageView *imagev = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"015.png"]];
imagev.frame = CGRectMake(0, -50, 320, 50);
[self.collectionView addSubview: imagev];
[self.view addSubview: _collectionView];
|