我有一个UIScrollview
包含默认高度为 1717px 的数据,在运行时我必须添加一个或多个子视图,每个子视图的高度均为 540px。事先不知道需要添加多少。
我将这些添加到viewdidload
方法中的滚动视图中,然后将其设置contentsize
为正确的值。我还将 contentsize 设置为我需要的任何值。如果我在方法结束时记录它一切都很好并且contentsize
仍然正确。
一旦显示它contentsize
已恢复到 1717 像素,但内容仍然存在。如果滚动超出 的正常范围,我可以查看添加的内容一秒钟uiscrollview
,但它会反弹回来。
我的相关部分viewdidload
如下
NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"counter" ascending:YES]];
for (Facade * f in [self.inspection.facades sortedArrayUsingDescriptors:sortDescriptors]) {
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"facadeView" owner:self options:nil];
facadeView *facadeInfo = [subviewArray objectAtIndex:0];
facadeInfo.facade = f;
facadeInfo.frame = CGRectMake(0, self.scrollView.frame.size.height, facadeInfo.frame.size.width, facadeInfo.frame.size.height);
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width, self.scrollView.frame.size.height+facadeInfo.frame.size.height);
self.scrollView.frame = CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height+facadeInfo.frame.size.height);
[self.scrollView addSubview:facadeInfo];
}
self.scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);;
// now add our scroll view to the main view
[self.view addSubview:self.scrollView];
我能做些什么来阻止我contentsize
重置为原始值?