UIViews inside a super or master UIView, display correctly in StoryBoard but shrink in the emulator - ios

I am quite new in swift programming and I am developing an app which has multiple custom views, hope some one can help me here.
The issue is that I have a scrollView, inside I have a stackView with about 20 Views inside, every view has inferred constraints and every view has a fixed height, maybe not the best practice but most of the views show correctly (had to re-do about 3 times to get here), but one of my views (around the middle of the stack) is showing correctly in my story board, but somehow it's shrinking it's subviews when launching the app, not sure if I am missing something, I have even removed all the content of these subviews and left only the main views with their heights but still I have the same issue.
To be more detailed the section that fails is a view inside the vertical stackView, it contains a view (container) which has the same leading, trailing, top and bottom as the first one. This container view, contains 5 (sub)views which have the same height each (124), and have practically the same content: a label, a texfield and a custom slider (thought the slider was ruining everything because it's custom but after removing all from the design the error still occurs).
Here is an image of how it's shown in the story board:
views in story board
And here is how it's displayed in the emulator:
view in emulator
Does anybody now why can this be happening? I am not doing any layout stuff in the code only a couple of corner rounding in other views that are inside the stack view.
BTW, I also implemented this 5 slider views using a vertical stack and had the same issue, I switched and changed to simple views and separated by 10 each bottom with the next view top.
Thanks

Related

Autolayout with stackViews inside a UIPageViewContoller Inside a Container View?

I’ve been struggling with this for a few days now…I can’t figure out how to correctly layout these constraints…. the bottom container view on the left is a UIPageViewController that loads the VC on the right…. that VC has a background view and 2 stackViews inside it… any ideas on how best to layout? I've tried constraining the leading and top of the background view to the safe area, then the same of the stackview (containing other stackviews) to the background view, but no matter what the stackviews display over each other?
The problem wasn't with auto-layout or my constraints, I was simply trying to fit too big of a view (the graph) inside it's superviews...when I shrunk the size of the graph, the existing constraints laid out the views perfectly.
To anyone else facing a similar issue however, Honey's comment is good advice, generally you should add the furthest "back" view first, add it's constraints, test to make sure it's correct, then repeat on each subview you add, as opposed to dragging all your views, then constraining them. The former is always the better approach. 👍

Swift - Scroll View smaller than Main View

I've many troubles with a ScrollView that is more little than main view.
My goal is the layout in the figure
where gray view is a TableView and blue is a hierarchy composed by a View inside the ScrollView. Everything is plaed all inside a main View. So the general hierarchy is the follow
In the ScrollView i've to put many elements, Switch for the final product, Label to understand. So i want the possibility to scroll.
Reading around the web i've found always the same, more or less, solution, this: one, two, three, four, five, etc.
As soon as i add various constraints as explained (for me are not all 0), both on the emulator and on the real device, the ScrollView disappears.
But as we see, in these example there is the case of a single ScrollView inside a main View, on full display. So i've tried also with another View to contain the hierarchy ScrollView-View. Unfortunately, i've the same results.
What is the problem? Where wrong i?
Control-drag from the content view of the scrollView to the viewControllers view and make Equal widths then change that constraint multiplier to 0.5 , same for the tableView sure minue margin between it and the scrollview
also make sure constraints are properly hooked from top to bottom
Here is a demo of what you want exactly scrollViewHalf

Placing views and elements within Scroll View

So I'm trying to get a layout to work using Scroll View.
Correct me if I'm wrong but from what I've been reading around the internet, it looks like to properly use Scroll Views and make it work with AutoLayout you need to have your root view, then put the scroll view inside it with constraints binding it to take the whole size of the root view (left/right/top/bottom constraints to 0) and then adding a view inside the scroll view and once again binding it to take up the whole space.
Afterwards, any ui elements or subviews would go in the innermost view.
My problem is that often I have experienced issues while settings my constraints within the scroll view where for example setting a trailing constraint to 0 wouldn't actually set to the end and so on, the numbers just wouldn't add up. In this case when I'm trying to make the innermost view take the whole space,it ends up messing it up more than anything; see image below.
Any help would be appreciated.
I just created this layout using the follow:
To test it, I added an image view to the content view and put a humongous image in it. It scrolls around quite nicely including bounce etc.
Update: You need to select your ViewController and uptick "Adjust Scroll View Insets"
Hope this helps.

iOS Contained View Controller Caused Auto layout Issues

I'm working on a project with a fairly complicated layout that I've developed programatically. The main view consists of 7 different sized views placed vertically with 6 spacer views in-between. All of the spacer views are constrained to be equally tall. According to a loop I'm doing with view.hasAmbiguousLayout, none of my views are ambiguous. I've been extra careful in checking all of the constraints, and the view acts as I expect on different device sizes.
The strange bit happens when I add a contained view controller. I've been using a contained view controller to manage a popup view. This subview has some transparency so I can see the main view below it. If this secondary view has any subviews at all, the main view's layout changes ever so slightly. The moment I add it some of the bottom views move slightly upward.
Is there a cause for this that I am missing or could it just be a bug in ios? (The same thing happens when I build the layout in interface builder)

scroll views working fine in iOS 7 with problems in iOS6

I hate iOS scroll views with auto layout, they are driving me crazy!:-D
I have found a method which works perfectly on iOS 7 to use scroll views:
I put the scroll view directly in the main view, attaching the scroll view to the edges of the super view(top,bottom leading and trailing space equals to 0).
Then I put a UIView into the scroll view attached to the edges of the scroll view, (top,bottom leading and trailing space equals to 0).
Then I set the height constraint of the most internal view, I link it at my ViewController class, and I modify its value programmatically.
Or, if the view it's 'static' I put every component using the storyboard into the internal UIView, starting with the one at the Top attached to the top of the super view, the one under, attached with the constraint 'Vertical Spacing' referred to the one over him..and so on... Until the last, which is also attached to the bottom of the UIView..
Everything works fine in iOS 7, it's perfect, but iOS 6 is messing around with the constraint.
When I first launch the view everything is perfect, but it seems to recalculate the constraints even on the didappear(and in a bad way), in fact, if I leave my view while it's scrolled down, when I come back to it(let's say we are in a navigation controller) , is like it's everything 'moved up' and the components at the top are hidden.
Is there a way to make scroll views work in both iOS 6 and iOS 7, I'n thinking at two storyboards as the only solution, please tell me there is another way... :-)
thanks everyone, I post two images explaining my problem, taken from the top of the screen:
Well uncheck use AutoLayout in file inspector and try.

Resources