1

I have a UIViewController that contains a UISegmentControl at the top, and a UITableView below. The layout is very simple. The UISegmentControl Top Margin is 16pts from the Top Layout Guide. The tableView is relative to the UISegmentControl. The view is part of a UITabBarController set. The UITabBarController is the storyboard's initial view controller.

I'm experiencing a problem where, on iOS 9 and 10, the UISegmentControl and the UITableView are positioned too high at initial app launch. As a result the UISegmentControl is partially obscured. If I switch to another tab or the next view in the hierarchy (by tapping a table cell), then go back to this view, the problem resolves itself.

The problem does not occur on iOS 11. The app doesn't support anything earlier than iOS 9.

Here are screenshots, taken both immediate after launch and then after switching to another tab then back again. Any suggestions appreciated.

Cold launch - segment bar obscured

fixed by tapping another tab then back again

Mitch Cohen
  • 1,551
  • 3
  • 15
  • 29

1 Answers1

0

Turn off extend edges under top bar :

Check your view controller attributes inspector in IB. Look for "Extend Edges" option under View Controller, and uncheck "Under Top Bars" if it is checked.

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • Thanks for the idea. Unfortunately self.automaticallyAdjustsScrollViewInsets = false has no effect. The views are still too close to the top at initial load, and correct themselves when the view comes back (after going to another tab). (I didn't change contentInsetAdjustmentBehavior because iOS 11 displays the views properly.) – Mitch Cohen Feb 02 '18 at 15:36
  • Did you try setting the segment top constraint to superview instead of top layout guide ? – Nitish Feb 02 '18 at 15:40
  • See if this works - https://stackoverflow.com/questions/20368875/uitableview-first-rows-are-cut-off-under-top-bar – Nitish Feb 02 '18 at 15:41
  • 1
    Bingo! Turning off “extend edges under top bars” was the answer. I set it in code to prevent any iOS 11 changes, but that did the trick. Feel free to edit your answer or post another answer and I’ll mark it – Mitch Cohen Feb 02 '18 at 16:06
  • 1
    Updated the answer. Good luck ahead – Nitish Feb 02 '18 at 16:08