晚回答我当时提出的问题。
由于我使用Autolayout,VChemezov的答案并不令人满意。
我的内容视图有一组顶部,底部,主要宽度的约束。 (宽度而不是尾随,这是我一开始做的事,但它不工作)。
所以现在我有这样的事情:
NSLayoutConstraint *leading = [NSLayoutConstraint
constraintWithItem:messageView
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.conversationScrollView
attribute:NSLayoutAttributeLeading
multiplier:1.0f
constant:0.0f];
NSLayoutConstraint *width = [NSLayoutConstraint
constraintWithItem:messageView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.conversationScrollView
attribute:NSLayoutAttributeWidth
multiplier:1.0f
constant:0.0f];
[self.conversationScrollView addConstraints:@[ top, leading, width ]];
随着内容视图等于滚动视图的宽度的宽度。
这帮助了我,我只是想补充具有自己内心的看法(消息查看在这种情况下),你可以复制在故事板这种行为连接到所有四个scrollView的两侧,但然后添加一个相等的宽度约束到scrollView。如果scrollView连接到超级视图,则会自动将contentView的宽度设置为超级视图的宽度。还处理定位更新。 – BreadicalMD