UIStackView resizing my views - swift

Im making a custom keyboard, and wanting a label and a textField centered in the space left over the keyboard, I figured the proper way would be to incorporate them in a UIstackView, and then centering the stack. However, i'm having som issues with the stack resizing my textField, causing whatever text i enter to be clipped.
I tried adding compressionresistance and a number of different solutions, but its clear to me that im missing some information about how UIStackViews work. Usually i make them work, but the whole resizing part I dont understand.
The first two screens are without a stack, adding them as subview to the viewcontrollers view, and the second screenshot shows the stackView resizing my textfield everytime the keyboard is resigned.
How can i stop the stackview from resizing its contained views?

It seems UIStackView is inherently a auto layout component, and when it adds your arranged subviews, it automatically positions them using constraints.
Since the UIStackView is adding constraints of its own, and the best way I found to stop it, was to simply explicitly set the subviews constraits:
textField.widthAnchor.constraint(equalToConstant: 300).isActive = true

Apple doesnt like dynamic StackViews: "In general, you should not use dynamic stack views to simply implement a scratch-built table view clone." Read the
Apple Documentation on UIStackView for details.

Related

How to set constraints to stack views?

I’m trying to achieve this layout using the interface builder
I’ve already tried to embedded the bottom button inside another stackview, also tried to set it out of the stack view but nothing works as expected what have now is this
And getting this result
Can someone tell me what constraints are missing or what is wrong with my current constraints?
You usually don't need to add too many constraints to the stack view's arranged subviews. Setting the distribution and alignment correctly is the key. The constraints involving Stop Button are either unnecessary or causing the conflict that you see in the console.
To position the stack view, you just need to pin its top, bottom, leading, trailing edges to the safe area. For example:
Then, set the alignment of all the stack views to "Fill", and the distribution of all the stack views to "Fill Equally".

Resizing Subview by User by Dragging Vertical Line

I try to find out if there is a chance to let the user resize a subview within an window by dragging a vertical line. The line is the NSBoxobject taken from the interface builder library. Both subviews (tableviewand textview) should resize itself in the horizontal direction by dragging the line during runtime.
Any hints? Thanks!
Please forgive me if I have miss understood your question as it seems very basic and I feel I’m missing something! Your request can easily be achieved through Storyboard Interface Builder, in your Object Library search both Vertical Split View and Horizontal Split View, these are great tools to allow the user to increase or decrease split view requirements. You can drop your desired views into either! And auto sizing will be maintained during user endeavours, alternatively Stack Views can maintain similar effects.

Autolayout - pull apart super view?

Is it possible to set height of super view relying on summarized height and padding between its child elements using auto layout?
Basically I'm trying to fill subviews with text from remote server, views are changing height dynamically, but their superview (or container view in other words) is static.
See -intrinsicContentSize and -invalidateIntrinsicContentSize. I believe this alone will get you there in simple cases. As I understand it, other things (including superviews with constrained distance from edges of a subview) will be moved to accommodate a view that claims a minimum size that would break those other constraints (keeping your view visible, for example).
I'd love it if others would chime in to validate/invalidate/correct me here. I'm still wrapping my own head around the many details specific to Autolayout in practice.

Automatically reposition views after UITextview resizes - iOS

For a simple example lets say I have a UITextView with a Button underneath it. These two controls are siblings both embedded in a parent UIView.
I now change the text within the UITextView and resize it accordingly. Is there a way to make the button automatically move to have the same relative distance to the bottom of the UITextView? This may seem trivial for this case, but I will have a longer hierarchy with multiple UITextViews that change and it would be nice not to have to calculate the height of every object manually.
One way to approach this would be with a table view: if you place each of your text views within its own table view cell, the table view will automatically calculate its total height from individual calls to its delegate’s -tableView:heightForRowAtIndexPath: method and lay itself out accordingly. Whenever the height of one of your text views needs to change, you can call -reloadData on the table view to make it lay itself out again. A disadvantage of this approach is that it’s really difficult to animate the height changes; if that’s essential to the effect you’re going for, I’m afraid you’re stuck with doing the entire layout manually.
Try the autoresizingMask property of UIView.

UIScrollView always bounce upwards and does not show scroll bar in iphone

This is probably simple but I do not seem to get it to work. I have a view and inside it I have a scroll view and inside it I have a view with some labels and a button. the height of the text inside the labels changes according to some condition so I need to scroll down to see it. But whenever I try to scroll down it bounce back up without giving me a chance to view the rest of the view.
Basically, I want when I scroll down, the view to remain down as it normally should. Besides I do not see the scroll bar at all when I'm scrolling.
I know I probably do not understand how scroll views work, so I'd appreciate any help to explain to me the behavior of scroll views.
P.S. I built my whole view in a nib file and this specific setup That I mentioned at the beginning is based on a suggestion from one question I read here.
Thanks, Mohsen
you need to set content size of your scroll view
[scrollView setContentSize:CGSizeMake(360,1000)];
you can make the content size dynamic as per your calculation.