UIScrollView可滚动内容大小歧义

本文翻译自:UIScrollView Scrollable Content Size Ambiguity

Fellow devs, I am having trouble with AutoLayout in Interface Builder (Xcode 5 / iOS 7). 资深开发人员,我在Interface Builder(Xcode 5 / iOS 7)中无法使用AutoLayout。 It's very basic and important so I think everyone should know how this properly works. 这是非常基本和重要的,因此我认为每个人都应该知道它是如何正常工作的。 If this is a bug in Xcode, it is a critical one! 如果这是Xcode中的错误,那就是关键!

So, whenever I have a view hierarchy such as this I run into trouble: 因此,每当我拥有这样的视图层次结构时,我都会遇到麻烦:

>UIViewController
>> UIView
>>>UIScrollView
>>>>UILabel (or any other comparable UIKit Element)

The UIScrollView has solid constraints, eg, 50 px from every side (no problem). UIScrollView具有固定的约束,例如,每侧50 px(没有问题)。 Then I add a Top Space constraint to the UILabel (no problem) (and I can even pin height / width of the label, changes nothing, but should be unneccessary due to the Label's intrinsic size) 然后,我向UILabel添加一个Top Space约束(没问题)(我什至可以固定标签的高度/宽度,什么都没有改变,但是由于Label的固有尺寸而不必要)

The trouble starts when I add a trailing constraint to the UILabel: 当我向UILabel添加尾随约束时,麻烦就开始了:

Eg, Trailing Space to: Superview Equals: 25 例如,尾随空格到:Superview等于:25

Now two warnings occur - and I don't understand why: 现在出现两个警告-我不明白为什么:

A) Scrollable Content Size Ambiguity (Scroll View has ambiguous scrollable content height/width) A)可滚动的内容大小含糊(滚动视图具有模糊的可滚动内容高度/宽度)

B) Misplaced Views (Label Expected: x= -67 Actual: x= 207 B)位置错误的视图(标签期望:x = -67实际:x = 207

I did this minimal example in a freshly new project which you can download and I attached a screenshot. 我在一个全新的项目中做了这个最小的示例,您可以下载该项目,并附上了屏幕截图。 As you can see, Interface Builder expects the Label to sit outside of the UIScrollView's boundary (the orange dashed rectangle). 如您所见,Interface Builder期望Label位于UIScrollView的边界(橙色虚线矩形)之外。 Updating the Label's frame with the Resolve Issues Tool moves it right there. 使用“解决问题”工具更新标签的框架将其移到那里。

Please note: If you replace the UIScrollView with a UIView, t

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值