iOS 7: Custom container view controller and content inset

前端 未结 6 624
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 05:15

I have a table view controller wrapped in a navigation controller. The navigation controller seems to automatically apply the correct content inset to the table view controller

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 05:27

    FYI in case anyone is having a similar problem: it appears that automaticallyAdjustsScrollViewInsets is only applied if your scrollview (or tableview/collectionview/webview) 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 {
        CGFloat top = self.topLayoutGuide.length;
        CGFloat bottom = self.bottomLayoutGuide.length;
        UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0);
        self.collectionView.contentInset = newInsets;
    
    }
    

提交回复
热议问题