Autolayout with UIScrollView

你。 提交于 2020-01-05 05:53:34

问题


I am using autolayout in Xcode and am creating a fairly tall (1300px) ViewController with a uiscrollview to navigate up and down. I made the viewcontroller freeform so its dimensions are [375,1300]. I then incorporated the scrollview, added the content view as well as all the subviews & constrained everything, leaving no constraint errors. At runtime there are no errors, but everything is all smushed into the normal screen size when I intended for it to be very tall (~1300px) and scrollable. Any clue as to what I am doing wrong?

Below is a diagram showing the issue where:

  1. The Outer Black Blox is the ViewController's view

  2. The Inner Black Boxes are subviews

  3. and The Blue Box is what is displayed on the screen


回答1:


Yes, your correct @Ryan Cocuzzo. I think you need to set sub view priority from 1000 to 250. See below screen shots.

1) Select height constraint of the subview

2)Then go to show to size inspector

3) Now change the priority constraint from 1000 to 250.

4)Finally you get like this




回答2:


Make sure the following are true:

  1. The 4 content views are subviews of the UIScrollView, not your view controller.
  2. The autolayout constraints on the 4 content views must reference the UIScrollView only, not the view controller's view.
  3. The 4th box cannot have a bottom constraint.

It looks like the 4th box has a constraint to make it's bottom align with the bottom of the view controller's view. This would force the other views to smush up together. The 4th box also cannot have a bottom constraint so that the scrollview can resize itself to encompass it's subviews.



来源:https://stackoverflow.com/questions/48068995/autolayout-with-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!