Set a view above navigation controller and below popupView - ios

I have a collection View with navigation bar on StoryBoard. There is a popupView that appears when custom cell is selected.
On main StoryBoard I set a View dimView to make dark background color while pop up view is showing.
However when I test on device, dimView does not go above Navigation Bar or TabBar.
I tried following code let window = UIApplication.shared.keyWindow! window.addSubview(dimView). But it makes dimView above pop up View.
I would like to set a view above navigation controller and below popupView.
Any idea how to solve this?

Have You try adding dimview on window but below popUp like this
let window = UIApplication.shared.keyWindow!
window.insertSubview(dimView, belowSubview: popupView)

Related

How to prevent view goes under UITabBar when using code to layout

I added UIViewController which has no storyboard to UITabBar.
It seems the view of added VC goes under the tab bar which does not
happen when I add a vc which used Storybaord to UITabBar.
How can I prevent this?
If you don't want the viewcontroller extend to any edges, you can try:
viewController.edgesForExtendedLayout = []
or viewController.extendedLayoutIncludesOpaqueBars = false should also work

How to overlap navigation bar by adding view in swift?

I want to make a custom side bar by adding a new view to the view controller, the side bar will be in the yellow color background. I want my side bar also to overlap the navigation bar/item (green background color) in my view controller. but the navigation bar/item seems can't be overlapped by my side bar view, it seems only overlap the main view.
I tried to find the answer in stackoverflow, I find this Overlap navigation bar on ios 6 with other view, but the answer is on the Objective-C, I can't read Objective-C :(
What should I do to overlap navigation bar/item ? here is the screenshot of my view controller
I embed the navigation controller like this
There are plenty of implementations of slide-over or drawer containers.
What you need to do to get above the navigation bar is CONTAIN the navigation controller inside another view controller.
The stack would look like this.
MasterViewController
UINavigationController
RootViewController
Menu
See this one here:
Swift version of MMDrawerController
You can do this by changing your UIViewController hierarchy. For this you'll need three view controllers. First will contain everything, let's call it MasterViewController; second—your main content with navigation bar; and third—drawer.
In MasterViewController instantiate child view controllers and add them to your view controller hierarchy in viewDidLoad().
final class MasterViewController: UIViewController {
override func viewDidLoad() {
let drawerViewController = DrawerViewController()
let mainViewController = MainContentViewController()
let navigationController = UINavigationController(rootViewController: mainViewController)
addChildViewController(drawerViewController)
addChildViewController(navigationController)
view.addSubview(navigationController.view)
view.addSubview(drawerViewController.view)
}
}
Now you have navigationController.view that you can place or animate anywhere within view.

swift: uicollectionview changes contentoffset of the cell during transition

I have a simple UICollectionView with a custom cell inside of a navigationController. For some reason when I push a viewController, the collectionView cell changes its layout during the transition.
Is it some common behavior of uicollectionview during viewController transition? Because, for example: labels don't have such problem
When back button was clicked
Green color from collectionView
Adding new view controller
navigationController?.pushViewController(controller, animated: true)
Setting Autolayout using EasyPeasy pod
collectionView.easy.layout([
Top(),
Right(),
Width(view.frame.width),
Bottom(10).to(button),
])
button.easy.layout([
Center(),
Height(60),
Width(300),
])
I think I've found your problem and it's in you AppDelegate. The property isTranslucent which is set to false to your navigation controller seems to cauese this rare problem. A translucent navigation bar will be on top of your viewcontroller's view, like above it. A non-translucent navigation bar pushes down your view controller's view or in other words rezising it so it fits beneath it.. But why the collectionview animates like it does is something I actually cant give a definite answer about. Maybe someone else could do that?..
To keep your navigation bar translucent you can set another property in your viewcontroller which is ´extendedLayoutIncluedsOpaqueBars´ to true.
So.. Do like this. In your AppDelegate:
window = UIWindow(frame: UIScreen.main.bounds)
window!.makeKeyAndVisible()
let controller = TestingNavigationController()
let navigation = UINavigationController(rootViewController: controller)
window!.rootViewController = navigation
let navigationBarAppereance = UINavigationBar.appearance()
navigationBarAppereance.isTranslucent = false
Then, in your view controllers viewDidLoad method add this line
extendedLayoutIncludesOpaqueBars = true
Hope this will solve your problem! :)
Apple Documentation about extendedLayoutIncludesOpaqueBars

Setting titleView of UINavigationItem makes titleView disappear

I've set the titleView of a UIViewController's navigationItem after init(). After pushing the VC to UINavigationController, titleView appears correctly at first time. But when I change (re-set) a titleView to an other view, it suddenly disappears.
But when I push another view controller and navigate back, it suddenly appears.
Do I have to perform any actions after re-setting the titleView?
If you are not using tab bar controller, then in viewDidLoad
setting the title as self.title is better.I have mentioned Tab bar Controller because if you have a view controller (in a NavigationController) in a UITabBarController, then if you set self.title it overrides the name of the tab as well as the top title.
I think you maybe code like this:
self.navigationItem.titleView = self.yourView;
If your yourView is a custom class , it maybe remove from superView when you switch your viewcontroller to next one;
So code like this maybe solve your problem:
[self.navigationItem.titleView addSubview:yourView];

How to present a UIViewController on top of my current UIViewController?

I'm doing everything programmatically. Not using storyboards.
I have a navigation bar at the bottom of my screen (like a tab bar, but custom made), with 5 options. I'd like to present a different view controller when each of those navigation options is clicked. However, I don't want the presented view controllers to cover my navigation bar at the bottom.
Ex: I have a settings button that can be pressed. I also have a SettingsViewController file. When a user clicks on the 'settings' button, I do
let settingsViewController = SettingsViewController()
settingsViewController.modalPresentationStyle = .OverCurrentContext
self.presentViewController(SettingsViewController(), animated: false, completion: nil)
but this covers my entire screen with a new view. When I change the color of this new view to UIColor.clearColor(), I can still see my navigation bar at the bottom but I cannot interact with it (the new view is on top of it).
I have tried to change the frame of my SettingsViewController view so that it does not cover the entire screen by putting
self.view.frame = CGRectMake(0,0,width,height-100)
in viewDidLoad() in my SettingsViewController. But the view still covers the entire screen!
I want my SettingsViewController to display only from the [top to 100px from the bottom] area of the screen. I want my navigation bar to remain in the bottom 100px of the screen. How can I do this?
Figured it out :)
I was trying to present my new SettingsViewController when all I needed to do was add the view from my SettingsViewController as a subview.
The solution is to do
self.view.addSubview(settingsViewController.view)

Resources