0

I am setting constraints in the SE View in the Story Board. For some reason the height of my view keeps getting stretched when i simulate in newer devices. I cannot understand what or why this is happening. I have tried:

-clip to bounds

-auto layout

-all content modes

-equal heights

All which are not working for me. Any input on how to avoid this?

Here is the link to the testProject(click Slow Download)

https://ufile.io/oxctp

enter image description here

enter image description here

husharoonie
  • 431
  • 1
  • 4
  • 19
  • could you please provide minimal example where this bug can be reproduced? – Serega Mar 10 '18 at 21:04
  • i dont believe this is a bug. Its a constraint issue. I just dont know how to avoid it or why its happening. – husharoonie Mar 10 '18 at 21:07
  • To understand why it's happening, example of XCode project is required. Screenshot doesn't contain enough info. – Serega Mar 10 '18 at 21:09
  • That is a very minimal example: throw a UIButton inside a View. Then put a textField above it and run it on different simulators with constraints. – husharoonie Mar 10 '18 at 21:17
  • With which constraints? Why can't you provide an example? It's very annoying to reproduce view content based on your description. – Serega Mar 10 '18 at 21:22
  • https://stackoverflow.com/help/mcve – Serega Mar 10 '18 at 21:23
  • Hold on ill send you a test project – husharoonie Mar 10 '18 at 21:27
  • @husharoonie if you like you need only send **the one storyboard file**. Note that - it's impossible to tell what you're trying to do - it may be you **do not at all need stack view here**. Is it possible your layout is nothing more complicated than connecting the top of the second element to the bottom of the first one??? – Fattie Mar 10 '18 at 21:33
  • I have posted testProject the link is above. Check it out so I can see what I am doing wrong. – husharoonie Mar 10 '18 at 21:39
  • NOTE: STAY on the SE View. I know its an easy fix switching views. But this specific example has to do with SE VIEW in storyboard. – husharoonie Mar 10 '18 at 21:45
  • Why do you set constants for your constraints explicitly? For example, Safe Area.bottom = View.Bottom + 365, EMail.top = Safe Area.Top + 154. On different resolutions your views will have different sizes. – Serega Mar 10 '18 at 21:45
  • what do you recommend I do instead? – husharoonie Mar 10 '18 at 21:46
  • It seems your don't understand how AutoLayout works. You should avoid using constants in AutoLayout and use intrinsic sizes of views. For example you could create one parent view with two children and center it in safe area. – Serega Mar 10 '18 at 21:51
  • It's difficult to write more detailed explanation here, just read Apple articles about AutoLayout and how it works with intrinsic sizes of views. – Serega Mar 10 '18 at 21:53
  • hushmeister .... it may be you do not at all need stack view here. Is it possible your layout is **nothing more complicated than connecting the top of the second element to the bottom of the first one???** Just set "vertical spacing" (to, say, 4 or 8) between the two items!!! **it's possible the solution is that simple** – Fattie Mar 11 '18 at 00:35

2 Answers2

2

Stack views are supposed to stretch like that !!!

You simply have your constraints wrong.

If you're already an autolayout expert, it is easy, just one click. But it's really impossible unless your storyboard is open in Xcode...

Some basic tips,

(1) try these two settings extensively:

enter image description here

You'll need to read every article on them, and all the source doco.

(2) make sure you are simply constraining the height of the stack view itself! If indeed, that is what you want. (There are many, many ways to do this and it depends on your layout. For example, it might be "some fixed height" or "80% of the height of some other element" .. or whatever, depends on you.)

(3) carefully review this article:

https://stackoverflow.com/a/40977494/294884

(4) Nobody has a clue what result you want, but if you do use a stack view, it's very likely you want to set the TOP of it, BUT NOT THE BOTTOM. In this way, the stack view will just become "whatever height is necessary" for the two elements in question. You could say the elements will set the overall height of the stack view, not the stack view. Sounds good?

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • BTW note that it almost certainly has nothing whatsoever to do with the hugging/etc priorities (as was mentioned in a deleted answer), which is a whole other level of complexity. – Fattie Mar 10 '18 at 21:31
  • the stackView doesnt make a difference in this case. I posted the sample project above. I under stand there is alot to learn and the complexity of constraints. I have found it is best to work from the bottom up to have the most success. I would just like to understand and overcome this issue of stretching on larger devices. – husharoonie Mar 10 '18 at 21:44
0

Try add missing constraints here:

here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Unreal Developer
  • 485
  • 3
  • 11
  • not a stackview bug. I put it in the stackView for constraint help. Ive been trying everything. – husharoonie Mar 10 '18 at 21:02
  • makes no difference with our without stack view. still getting the same result. – husharoonie Mar 10 '18 at 21:03
  • is fixed height impossible for your case? – Unreal Developer Mar 10 '18 at 21:07
  • I dont have "Missing Constraints". – husharoonie Mar 10 '18 at 21:13
  • You almost certainly do have missing constraints, or, they're just wrong. When you read articles on the net about iPhone development, it suggests it's very easy and that within two months you'll have a hit! on the app store. in fact, it is **extremely, extremely**, difficult. For example, we've been trying to hire a true autolayout expert for a year - they don't exist. You could easily spend say 8 weeks, continuously, 50 hours a week, becoming expert in UIStackView. – Fattie Mar 10 '18 at 21:30
  • regarding this answer, I would **very strongly recommend never, ever - ever - using that button**. You could go so far as to say "it does not work properly". **Normal procedure** with constraints is, in the explorer on the left you hold down "control" and DRAG to the other element you want to constraint to. Then, use the menu which appears. There is a **lot to learn**. – Fattie Mar 10 '18 at 21:35
  • @Fattie im agree with you. just when it adding missing constraints - you can check what did you miss, then edit all the constraints by hand whatever you want – Unreal Developer Mar 10 '18 at 22:24
  • fair enough @UnrealDeveloper ! – Fattie Mar 11 '18 at 00:33