iOS7: UICollectionView appearing under UINavigationBar

后端 未结 5 1147
囚心锁ツ
囚心锁ツ 2021-02-01 06:56

I\'ve been building on iOS 7 for a while now but I\'ve yet to get this solved, I have a number of views with autolayout enabled that were created in Storyboard and are displayed

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 07:04

    FYI if your UICollectionView is the root view in your view controller's hierarchy and your view controller has automaticallyAdjustsScrollViewInsets set to YES (this is the default), then the contentInset should update automatically.

    However, the scrollview's contentInset is only automatically updated if your scrollview (or tableview/collectionview/webview btw) is the first view in their view controller's hierarchy.

    I often add a UIImageView first in my hierarchy in order to have a background image. If you do this, you have to manually set the edge insets of the scrollview in viewDidLayoutSubviews:

    - (void) viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
        CGFloat top = self.topLayoutGuide.length;
        CGFloat bottom = self.bottomLayoutGuide.length;
        UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0);
        self.collectionView.contentInset = newInsets;
    
    }
    

提交回复
热议问题