iOS 7 Table view fail to auto adjust content inset

前端 未结 7 1646
情话喂你
情话喂你 2020-12-04 14:24

I am transiting my project to iOS7. I am facing a strange problem related to the translucent navigation bar.

I have a view controller and it has a tableview as subv

7条回答
  •  春和景丽
    2020-12-04 14:58

    If you want the view to underlap the navigation bar, but also want it positioned so the top of the scrollview's content is positioned below the navigation bar by default, you can add a top inset manually once the view is laid out. This is essentially what the view layout system does when the top-level view is a scroll view.

    -(void)viewDidLayoutSubviews {
        if ([self respondsToSelector:@selector(topLayoutGuide)]) {
            UIEdgeInsets currentInsets = self.scrollView.contentInset;
            self.scrollView.contentInset = (UIEdgeInsets){
                .top = self.topLayoutGuide.length,
                .bottom = currentInsets.bottom,
                .left = currentInsets.left,
                .right = currentInsets.right
            };
        }
    }
    

提交回复
热议问题