Unable to put view above navigation bar - ios

I am trying to design a side menu, whose height would be equal to screen height (therefore hiding the navigation bar too). However I am unable to get the same.
I have put constraints as this:
and in viewDidLayoutSubviews()
I have mentioned - sideMenuTopConstraint.constant = -1 * (self.navigationController?.navigationBar.frame.height)!
However I see no change. Also by increasing the height of the side menu view in storyboard, I see that it is always below the nav bar. How do I make it appear above it?

You need to add the view to window as a subview, that should bring this view above the navigation bar as needed.
This is because window is the root of all the views.
UIApplication.sharedApplication().keyWindow?.addSubview(desiredViewHere)

Related

UICollectionView under Navigation Bar, but not under Tab Bar

I have a UICollectionView that I want to go under the navigation bar. Basically I want it to ignore the entire top safe area, yet still want it to respect the bottom safe area, as there's a tabbar there. This is how it currently looks:
But I want the first cell to start directly the very top of the screen, under the (translucent) navigation bar and the status bar.
If I set collectionView.contentInsetAdjustmentBehavior = .never, then the top part works great, but then the bottom part of the collection view content is hidden by the tabbar - you can't scroll all the way to the bottom so to speak. So I have to manually add a bottom inset again? How do I get the height of the tabbar, including any bottom safe area on devices that have the home bar? Or is there a better way to tell the collectionview to ignore only the top area for its content inset adjustment?
You just need to set the bottom content inset of the collection view manually, after setting the adjustment behavior to .never.
The correct inset (including the tab bar and any home bar) can be found in safeAreaInsets.
collectionView.contentInsetAdjustmentBehavior = .never
collectionView.contentInset.bottom = collectionView.safeAreaInsets.bottom
You'll need to do this at a point when the safeAreaInsets have been set, such as viewDidLayoutSubviews.
As far as I remember, it used to be possible by simply adjusting the edgesForExtendedLayout property of the containing view controller, but that was phased out when safe areas were introduced in iOS 11 I believe.

Adjust Navigation Bar width inside NavigationController

I am trying to implement a horizontal scrolling table view. I was able to accomplish this with the following layout. I have a ScrollView which contains a Container View which points to my NavigationController. Since I made the Container View wider than the ScrollView, the table is able to scroll left to right as expected.
The problem I am having is resizing the Navigation Bar's width as I do not want to have to scroll to view the Navigation Bar's title. I tried explicitly setting the width property of the Navigation Bar in ViewDidAppear however it keeps getting resized to the actual width of the table view. Is there any way I can do this without having to create my own custom view that mimics that Navigation Bar?
I ended up creating my own navigation bar that is placed on top of the actual integrated table view navigation bar.

Remove the gray bar at the bottom of view controller - iOS

The image shows the View controller and the bar I want to remove. And also the structure of the view controller:
Someone told me how to remove the grey bar present at the bottom of the view controller as shown in the image. Unable to select and delete the bar. When I try to add the tab bar in that place, it goes behind the grey bar and becomes invisible.
What do your simulated metrics look like?
Can you get rid of the bar by changing the bottom setting?
Couple of things - if you are using autolayout, just make a constraint to the bottom of the container, with 0 value for the constraint. That will take it to the bottom. Second thing I would add is a zero size table view footer to the tableview.
This is a toolbar that comes with the UINavigationController that the View Controller is embedded in. Assuming you have a Navigation Controller on the storyboard connected to the view controller, select it and in the attributes inspector deselect "Shows Toolbar". If you want to do this in code you can get and set isToolbarHidden on a UINavigationController instance.

UIPageController inside UINavigationController is offset from the top?

This a little bit wierd i have made UIPageController that works and everything is fine. But when i put it inside UINavigationController, it offset from the for status bar. Than i swipe up on that screen it positions itself right and everything is ok. I don't really understand what is happening. Here are the images
try setting adjustScrollViewInsets to false on UIPageController.
This is the property that determines whether the system should automatically add inset to a UIScrollView in your view controller's view hierarchy when it is being displayed behind transparent bars (here , the navigation bar). What happened here is that the system assumed the bounds of the page controller overlaps with that of the nav bar and so it adds insets so that the view's contents is fully visible and is not obscured by the nav bar. But in this case it is wrong since it seems your page controller's bounds starts at the bottom edge of the nav bar.
I think you can also set the nav bar as opaque to disable the automatic adding of insets.

Adding a view above UINavigationBar

I'm trying to add a custom view above the navigation bar as displayed on the following image .
What I've tried so far is to add the view as a subview of the navigation bar - Did not work
Add the custom view first on Interface builder and then add a navigation bar manually - This seems to mess up with my navigation as the default navigation controller has it's own navigation bar.
Is this a bad approach on its own ?
If this is a view that will appear above all navigation bars in the app, why not use a Container View?
Make the Container View fill the screen, but give it a 20 point top margin to fit your custom green view. Then when you add your main view controller (wrapped in a navigation view controller) to the Container View, it will show your green view above it.
If you don't want your margin in a particular screen, do the following:
Add a constraint to the top margin and add an outlet to it so you can modify the constraint's constant in code.
Then, in any screens where you don't need the margin, access the parent view controller view and set the constraint's constant to zero.
let myParentViewController = self.parentViewController as? MyParentViewController
myParentViewController.myTopMarginLayoutConstraint.constant = 0
Don't forget to reset it to 20 (or whatever) when you go to a screen where you need the top margin again.

Resources