简体   繁体   中英

iOS-Swift-The location of collectionView header

I want to add the header in the collectionView but I have no idea how to delete the blank space between navigation bar and cell. Does any one give me some advice? Thanks.

The ViewController is below.

class CelebrityVC: UIViewController, ButtonDelegate, UICollectionViewDataSource, UICollectionViewDelegate {

var  collectionView:UICollectionView!
let reuseIdentifier_header = "CelebrityHeader"
let reuseIdentifier = "listviewcell"

override func viewDidLoad() {
    super.viewDidLoad()

    MakeBarButton(self)

    let screenWidth = getScreenWidth()
    let screenHeight = getScreenHeight()
    let flowLayout = CSStickyHeaderFlowLayout()

    collectionView = UICollectionView(frame: CGRectMake(0, self.navigationController!.navigationBar.frame.size.height+statusBarHeight() ,screenWidth,  screenHeight-(self.navigationController!.navigationBar.frame.size.height+statusBarHeight())), collectionViewLayout: flowLayout)
    collectionView.backgroundColor=UIColor.whiteColor()
    collectionView.delegate=self
    collectionView.dataSource=self
    self.view!.addSubview(collectionView)

    let nib = UINib(nibName: "ListViewCell", bundle: nil)
    collectionView.registerNib(nib, forCellWithReuseIdentifier: reuseIdentifier)

    let nib_header = UINib(nibName: "CelebrityHeader", bundle: nil)
    collectionView.registerNib(nib_header, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: reuseIdentifier_header)

    self.collectionView?.registerClass(CelebrityHeader.self, forSupplementaryViewOfKind: CSStickyHeaderParallaxHeader, withReuseIdentifier: reuseIdentifier_header)

enter image description here

只需在您的ViewDidLoad方法中添加它

self.automaticallyAdjustsScrollViewInsets = NO;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM