Ios UIScrollView contentsize在使用Autolayout时未显示全部内容?
我有一个包含许多UIView的scrollView。这些UIView的一部分在序列图像板中设计,其余部分在代码中。因此,我的自动布局约束在代码和序列图像板中。现在,序列图像板中应用的约束的视图显示得非常完美,即scroll view的内容大小正确地显示它们。但是对于设计的UIView在代码中,滚动视图的内容大小不会更新 这就是我设置滚动视图内容大小的方式Ios UIScrollView contentsize在使用Autolayout时未显示全部内容?,ios,objective-c,uiview,uiscrollview,Ios,Objective C,Uiview,Uiscrollview,我有一个包含许多UIView的scrollView。这些UIView的一部分在序列图像板中设计,其余部分在代码中。因此,我的自动布局约束在代码和序列图像板中。现在,序列图像板中应用的约束的视图显示得非常完美,即scroll view的内容大小正确地显示它们。但是对于设计的UIView在代码中,滚动视图的内容大小不会更新 这就是我设置滚动视图内容大小的方式 -(void)setScrollViewContentSize{ //scroll view content size according
-(void)setScrollViewContentSize{
//scroll view content size according to no of views.
CGRect contentRect = CGRectZero;
for (UIView *obj in self.eventScrollView.subviews) {
contentRect = CGRectUnion(contentRect, obj.frame);
}
self.eventScrollView.contentSize = contentRect.size;
}
我在代码中应用以下约束
UIView *submitView = [[UIView alloc]initWithFrame:CGRectMake(6, 1051, 308, 30)];
// set autolayout
submitView.translatesAutoresizingMaskIntoConstraints = NO;
[submitView addConstraint:[NSLayoutConstraint constraintWithItem:submitView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:submitView.frame.size.height]];
[submitView addConstraint:[NSLayoutConstraint constraintWithItem:submitView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:submitView.frame.size.width]];
[self.eventScrollView addSubview:submitView];