How to make a view controller adopt the same size as its distant ancestor's container view? - ios

This will be easiest to explain with a diagram:
Here the initial view controller has a container view which contains the tab bar controller (note that the red bar at the top is a view, the initial view controller is NOT a navigation controller).
Any views displayed by the tab bar controller will occupy the same dimensions as the container view. Therefore when the blue VC is displayed the screen will continue to show the red view.
If when the button on the blue VC is clicked the green VC is presented modally and it occupies the full screen and thus covers the red view.
My question is, is there a simple way to make the green view controller occupy the same dimensions as its grand parent's container view so that the red view will be visible when the green VC is displayed.
(By simple, I don't want to do anything involving strong coupling such as the green vc obtaining the explicit dimensions of the container view and setting its dimensions to match. I'm hoping there's a setting in the storyboard or a different way of presenting the vc which will result in it automatically adopting the same size as its parent).
Yes I know the intitial view controller could be a navigation controller, we don't need to discuss why its not.

Related

Slide in/out child view controller partially visible on parent view controller in Swift

I have built two separate UIViewControllers: MainVC and 2ndVC. Now I am trying to connect them and achieve the effect presented on the image below:
When loaded, 2ndVC should be visible partially on top of MainVC (let's say 1/4 of the screen). On swipe up 2ndVC should cover whole screen and on swipe down it should go back to starting point. I have some buttons on MainVC which I would like to stay active when 2ndVC does not cover whole screen.
2ndVC's height will change dynamically dependently on data. It has scrollview inside which should be active only when it covers whole screen.
What is the best way to do that? Should 2ndVC be embedded in container view as a child view controller? Should I somehow animate constraints of 2ndVC programmatically on swipe?
Probably a Container View Controller is what you are looking for:
https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

In a container view, a navigation controller's navigation bar not resizing to include status bar

I have created an application which needs to have a bar above the navigation bar and other views. To accomplish this, I am using a view controller with a view for the top bar, and then a container view for everything else. Sometimes, the top bar needs to be hidden. I'm using autolayout to hide the top bar (set its height to 0), and the container view expands to fill the screen (container top equal to the top bar bottom). The container view contains a navigation controller because I need a navigation bar below the top bar sometimes. When I start the app, this all works fine as shown below:
As you can see, the navigation bar stays the desired height, which is expanded to include the status bar
However, when the top bar is tapped, I use a segue to present (not push) a view controller from my root view controller (not the container), and then I look at the same screen with the navigation bar, the navigation bar is no longer extended and it overlaps the status bar as seen below:
Why would presenting a view controller break this? And then how could I rectify this or prevent it?
One possible solution I could do is present a view controller from within the container view, that works, I would just have to set the current view controller in the container to a delegate of the root controller, so that when the top bar is tapped, it tells the view controller in the container to present the new view controller. This would not be my first option however, especially if there are other scenarios which cause this problem.
Thanks for any help!
You need to turn automaticallyAdjustsScrollViewInsets off for all of your child view controllers and manage the insets (or setup so they aren't required) yourself. By default automaticallyAdjustsScrollViewInsets is on for all view controllers (which is what you want for 'full screen' presented VCs.
At the moment you see controllers almost randomly updating to reorganise themselves for the scroll insets as the VC hierarchy changes.
I'd probably turn automaticallyAdjustsScrollViewInsets off for all VCs (apart from root) and change your header view so that it's full height or status bar height (which should be the length of the topLayoutGuide of the root VC). When collapsed to status bar height your header view could also change colour to match that of the current top VC.

How to create a view above navigation bar or other screen content?

I would like to have a view above the navigation bar, or above any screen content if there isn't a navigation bar on that screen, so that it essentially reduces the height of everything else and doesn't cover any content. I also would like this view allow interaction (i.e. if its tapped, it would do something).
I have tried
UIApplication.sharedApplication().keyWindow?.addSubview(view) but that just overlays the view.
Here is a visualization:
Don't think of it in terms of above, think of it as beside - a sibling view.
So, create your own root view controller with that view and a container view below it, then add your 'normal' root navigation controller (or whatever) as a child view controller into the container view.

Can I place a UIView the current Navigation Controller?

How can I place a UIView overtop of a Navigation Controller? Is this possible without making my own custom navigation bar and custom tab bar controller out of UIViews?
Let's say I have a UITabBarController and I want to present a blur view overtop of the entire thing. For the blur view, I'm using the UIVisualEffectView. But i want the blurview to take up the entire screen including the top navigation bar and the bottom tab bar. If I push a new view controller, that will take up the entire screen, but then I can't see through it to what's underneath (the tab bar controller's contents).
I could simply hide the navigation bar and tab bar when I animate in the blur view, but that looks awkward because you see the content in the collectionview shift because the navigation bar is hiding... I'd rather not see that shift in the content when the blurview comes up.
Here's a UITabBarController with stuff in it.
I want a blur view to cover everything and to be able to see through to the entire UITabBarController and the stuff underneath.
One way is to add the UIView as a subview of the key window. See this post for how to get the key window. However, it's generally best to keep to your own view hierarchy, so...
Another way might be to present a new view controller as a fullscreen modal, and apply the blur/transparency to that modal view.

DetailViewController in SplitViewController Displaying in Wrong Position

I'm using a storyboard and auto-layout for an iOS 7 project. I have a SplitViewController with the master view controller and detail view controller relationships set. The master view controller is correctly displaying aligned left, but the detail view is displaying centered, behind the master view, not aligned left like it should be: https://dl.dropboxusercontent.com/u/12009928/2014-03-19%2021.50.43.png
How can I fix this?
Have you checked the view on the Detail Controller, is it properly aligned to the edge of the view controller. Trying giving background colour (other than white) for your Detail View Controller and View to troubleshoot the issue

Resources