Container View getting pushed down as if it had a UINavigationBar?

前端 未结 8 954
既然无缘
既然无缘 2020-12-08 06:13

I have a UIViewController with a Container View. This Container View contains a UITableViewController.

The UIViewController is embedded in a UINavigationController.

相关标签:
8条回答
  • 2020-12-08 06:55

    If this issue occurs with a storyboard (without touching the translucent property in the code), I found it helpful to check the NavigationBar settings and - if necessary - the storyboard source file.

    (This does not fully apply to this question, but when I searched for the issue, basically only this question popped up and maybe the information helps others with the same issue.)


    The details:

    To access the Navigation Bar in the storyboard editor: Show the Document Outline (menu Editor -> Show Document Outline), select the Navigation Bar.

    Navigation Bar in Document Outline

    Then in the Utilities Pane on the right hand side in the Attributes inspector make sure, "Translucent" is unchecked.

    Translucent Propterty

    If this does not help, open the storyboard file in TextEdit, look for the navigationBar element and check for opaque or translucent attributes. You want translucent="NO".

    StoryBoard Source

    (To open the storyboard source: In Xcode in project navigator right click on the storyboard file. Select "Show in Finder" and in the Finder window, right click on the file and select "Open with..." and select TextEdit.)

    EDIT: (I don't know, whether it was there all the time, but one can right click on the storyboard file in the project navigator and select "Open As" -> "Source Code". No need to go to the Finder.)

    0 讨论(0)
  • 2020-12-08 06:55

    I fixed this issue by going into IB > Select the view > Deselect "Adjust scroll bar insets"

    0 讨论(0)
  • 2020-12-08 06:58

    The above mentioned in the above answers did'nt work for me.When translucent is NO my ViewController pushes downwards which is embeded in Navigation controller. The solution worked for me is shown below

    1. Go to Attributes Inspector
    2. Select 'Extend Edges' by ticking the checkbox titled Under Opaque Bar

    The screenshot is atatched

    I am using Xcode 9.

    Thanks

    0 讨论(0)
  • 2020-12-08 07:00

    What you are missing here is that a translucent navigation bar sits on top of your viewcontroller's view, while a non-translucent navigation bar pushes down your view controller's view (effectively resizing it).

    So what is happening here is that with a translucent navigation bar, that white space is actually hidden underneath the bar, while when the bar is not translucent it's "pushed down".

    There are a number of ways to go about it, and it mainly depends on whether you're using auto layout or not.

    0 讨论(0)
  • 2020-12-08 07:07

    As of iOS 7.0, all views automatically go behind navigation bars, toolbars and tab bars to provide what Apple calls "context" – having some idea of what's underneath the UI (albeit blurred out with a frosted glass effect) gives users an idea of what else is just off screen.

    If this is getting in your way (and honestly it does get in the way surprisingly often) you can easily disable it for a given view controller by modifying its edgesForExtendedLayout property.

    For example, if you don't want a view controller to go behind any bars, use this:

    edgesForExtendedLayout = []

    Available from iOS 7.0

    Source

    0 讨论(0)
  • 2020-12-08 07:11

    I fixed this issue by adding this line of code in -viewDidLoad:

    self.extendedLayoutIncludesOpaqueBars = YES;
    
    0 讨论(0)
提交回复
热议问题