问题描述
我用故事板和经销商的布局,使其工作在两个iPhone4和iPhone5的良好创建iOS应用。下面是我用故事板创建视图的屏幕截图。结果
I'm creating iOS app using story board and auto layout so that it will work good on both iPhone4 and iPhone5. Below is the screen shot of the view that I'm creating using story board.
在上面的图片,我想保持滚动视图从上海华的领先优势和右表视图中间。我不想滚动视图,以增加其在iPhone5的宽度。我试图约束的不同组合,但我无法实现这一目标。结果
In the above image, I want to keep the scroll view in the middle from leading edge of superview and the right table view. I dont want the scroll view to increase its width in iPhone5. I tried different combinations of constraints, but I couldn't achieve it.
一些建议我是什么,我已经为滚动视图设置,以便它会在中心内的所有限制。
Can some suggest me what are all constraints that I've to set for scroll view so that it will be in center.
推荐答案
您将需要添加额外的视图屏幕做到这一点。
You will need to do this by adding an additional view to the screen.
在你的那一刻......
At the moment you have...
- UIView (main view)
|
| - scrollView
| - tableView
您应该把滚动视图这样其他视图里面...
You should put the scroll view inside another view like this...
- UIView (main view)
|
| - UIView (spacer View)
| | - scrollView
|
| - tableView
现在你可以做的是有这些约束......
Now what you can do is have these constraints...
spacer view leading edge constraint to super view = 0
spacer view trailing edge to table view leading edge = 0
table view width = (whatever the width is)
table view trailing edge to super view = 0
这将为走出隔离视图和表视图,这样,间隔看法会越来越大。
This will lay out the spacer view and the table view so that the spacer view will grow.
现在,您需要添加...
Now you need to add...
scroll view width = x
scroll view height = y
scroll view centered vertically in super view
scroll view centered horizontally in super view.
现在,由于滚动视图的超级观点是间隔观点则总是在表视图和空间的其余部分之间的中央。
Now, because the scroll view's super view is the spacer view then it will always be centered in between the table view and the rest of the space.
这篇关于iOS版 - 用故事板和自动布局居中的UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!