我正在尝试使我的uiimageView高度动态动态,但它不起作用。该结构是
[UIView]
[UIScrollView]
[UIImageView]
[UILabel]
[UILabel]
[UITextField]
[UIButton]
[UIButton]
除imageView外的所有内容固定高度,并且应始终从底部开始在屏幕上看到,无论屏幕中剩余的空间如何,imageView都应适合其中(ImageView高度应在“输入您的手机号码”标签之间调整自动屏幕上的顶部不应
。
滚动 “ https://i.sstatic.net/zebxc.png” rel =“ nofollow noreferrer”> 
I am trying to make my UIImageView height dynamic but it is not working. The structure is
[UIView]
[UIScrollView]
[UIImageView]
[UILabel]
[UILabel]
[UITextField]
[UIButton]
[UIButton]
Everything except ImageView has fixed height and should always be seen in the screen starting from bottom, and whatever the remaining space in screen, the ImageView should fit in it (imageview height should adjust auto between the "Enter your mobile number" label and top of the screen. The screen shouldn't be scrollable. Used scrollView only so when keyboard appears, user should see what they are typing.
Issue is imageview is being set is weirdly large height and screen is scrollable :S

发布评论
评论(1)
首先,在发布这样的问题时,有几个提示...
例如,此屏幕截图几乎什么都没有告诉我:
将其与此屏幕截图进行比较:
我现在可以看到恰好对布局和约束所做的事情。
因此,要解决您的问题...
您需要将所有这些元素嵌入
uiview
- 我将其称为contentView
。我假设您的滚动视图被限制为填充安全区域。要添加到滚动视图的第一个元素是
contentView
。将其顶部,底部,领先和尾随到滚动视图的内容布局指南上,每侧有20分(在左/右侧给我们“填充”)。然后,将其高度限制等于滚动视图的框架布局指南高度,其宽度等于滚动视图的框架布局指南宽度宽度为
-40
(请记住,每一侧为20点)。现在,我们可以将所有UI元素添加为
contentView
的子视图,并按照平常的方式约束它们。因此,在该图像中:
,我们可以看到所有约束。
而且,无论我们是使用“短”或“高个子”设备,图像视图“伸展”以填充“可用顶部区域:
这是该故事板的来源,以便您可以在细节:
First, a couple tips when posting a question like this...
For example, this screenshot tells me almost nothing:
Compare that to this screenshot:
I now can see exactly what has been done with the layout and constraints.
So, to solve your issue...
You'll want to embed all of those elements in a
UIView
-- I'll call itContentView
.I'm assuming your scroll view is constrained to fill the safe-area. The first element to add to the scroll view is the
ContentView
. Constrain its Top, Bottom, Leading and Trailing to the scroll view's Content Layout Guide, with 20-points on each side (to give us "padding" on left/right).Then constrain its Height equal to the scroll view's Frame Layout Guide Height, and its Width equal to the scroll view's Frame Layout Guide Width with a Constant of
-40
(remember, 20-points on each side).Now we can add all of the UI elements as subviews of the
ContentView
and constrain them as we normally would.So, in that image:
and, we can see ALL of the constraints.
And, whether we're on a "short" or "tall" device, the image view "stretches to fill" the available top area:
Here's the source to that storyboard so you can inspect it in detail: