Autolayout whem view are hidden - ios

I know that there is 2 approaches when dealing with autolayout and hidden views:
Remove hidden view from hierarchy and add it back when needed
Change UIViews constraints to ignore hidden view
I have some complex case (imo). Here is my layout
Gray view is container view in my hierarchy on the left.
I have 3 blocks: green, yellow and red. Red and yellow also have titles (see small rects of the same color).
So the problem is that yellow and red could be empty. Adding view back would have rather difficult code (for example adding red):
I have to check if yellow block is here
I have to set lots of constraints in code. I could easily break my UI by changing constraints on Storyboard and not change it in code.
I need to hide red/yellow views when there is no info and show them again when there is some info (without reloading whole controller)
Are there any solutions without that problems?

Related

How to place any view below any other view which is getting it's position from code

I've created 4 subviews of white color & a yellow one as you can see in reference image I've shared below.
And I've programmatically changed the position of Tabbar from bottom to top just below to navigation bar as you can see in below image (When it is running in the simulator).
Now since I've constraints for that yellow view in image as follow
It is appearing just below to navigation bar but I want it to be displayed just below the Tabbar.
Since Tabbar is getting its position programmatically & other views (including yellow view) are getting their positions from the storyboard.
And since storyboard UIelements are get settled before any other UIelement which are coming from the program or at least get their position from programmatically.
What could be the best way to achieve what I want.
Please refer my storyboard as well to get more understanding. (Refer Below image)
I also want to fit all 5 subviews in the space between tabbar & bottom of the screen. I want to calculate 1/5th of that space & assign this height to each subview. I'd later reduce few pixels to separate them.
Why not add the height of the tab bar to the yellow view's top position? That way, you'd set the constraint something like:
Fajar.top = top + 44
If the tab bar is always visible, then that should work. But of course, if the tab bar only appears at times, you'd probably have to change that constraint programmatically depending on the change ...

Why does Interface Builder show hidden views through the views above them?

When nesting views in Interface Builder, if I have an opaque view with hidden views beneath it in the view Hierarchy, the hidden views are visible through the higher view and are just partially translucent like the below picture.
Why does this happen and can I make it stop? It's very annoying.
To be clear this is strictly in IB. At run time the views are displayed correctly.
Sad to see this is the best answer that I have found so far: If you set the view you want to work as NOT hidden, while all the rest ARE hidden, then you can select away from the storyboard (e.g. some other file), then click back on the storyboard. Only the NON-hidden views are displayed. Sadly, the other views comeback if you make position alterations to the view (UPDATE: only when you click and drag. Selecting and using arrow keys does not), but changing text, size, color etc do not.
Original with hidden
Clicked off storyboard and back

Empty navigation bar appearing in subview

I am trying display a UITableView within a larger UIView in an iPad app, mainly because the data is pretty sparse and I'd like to have the table be a smaller area over a background image, rather than taking up the whole screen. The parent UIViewController is correctly set as the table data source and delegate, and the table looks/functions like it should. The whole view is embedded in a navigation controller; the overall UIView shows a navigation bar, as it should, that I can configure normally.
The problem is the UITableView subview also shows blank space at the top for a navigation bar--empty space above the first cell--and I can't figure out how to get rid of it. I know the space is related to the navigation controller, because when I delete the embed link in the storyboard, the space goes away. The table view doesn't present a UINavigationBar property or any other navigation-related properties that I can try to nullify.
I would post a screen shot but I don't have the rep yet.
Can anyone explain where the space is coming from and how to nix it?
I suspect the answer is related to the Top Layout Guide for the view, but I can't diagnose the specific problem.
Here's a workaround from the storyboard: Insert a UIView in the scene, then drag the UITableView into it as a subview. Check the box for the new UIView's "Clip Subviews" in the attribute window, and then use it as a mask, basically, to cover the undesired top margin of the table view. It works and doesn't require any coding, but there has to be a better way.

Why there is a border around the UIView?

In my story board I have added a new custom view controller. It is 'connected' to the RootView Controller via a push segue.
This is the new custom UIViewController as seen in the storyboard
When I run my app in the simulator, I can see a border around the frame. (Of course it is visible because I set a background color to RootViewController)
I want to understand:
1) Why my custom view controller does not occupy the whole frame?
2) what is the orange color dotted line? Is it related to the question 1? What is the best practice (i.e. is the border a new behaviour and is not indicative of bad design etc)?
The orange dotted line shows that the view will change when the constraints are resolved, and shows where the view will end up.
If the view is correct in Interface Builder, just go to the Resolve Auto Layout Issues popup menu and select Update Constraints. That will update the constraint values to match the layout in Interface Builder.
If you select Update Frames instead, that will make the view match the constraints (causing the view to shrink to the orange dotted line in this case).

Conditional overlapping view transparency?

I have a few moving views which are semi-transparent, at some point they will be overlapping. Is it possible to make the overlapped part "invisible" through the top most view?
For example, 3 UIViews a background (which is stationary) and 2 subviews (the semi-transparent ones) and when they overlap the lower subview will be "invisible" under the top subview, all the while i can still see the background view and the part of the lower subview which isn't overlapping the other view.
Here's an image to help clarify the before and after they overlap.
Before Overlap:
After Overlap:
(the view on the far right looks a little strange because it blends with the white background)

Resources