我有一個UIScrollview
包含默認高度爲1717px的數據,在運行時我必須添加一個或多個子視圖,每個子視圖540px高。事先未知其中有多少將不得不被添加。UIScrollview重置內容
我添加這些在viewdidload
方法滾動視圖,然後設置contentsize
爲正確的值。我還將contentize設置爲任何我需要的值。如果我在方法結尾記錄它,一切都很好,contentsize
仍然正確。
一旦顯示contentsize
已經恢復到1717px,內容仍然存在。如果我滾動到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
?
滾動視圖的大小是好的,在循環後它會變回正確的值。它主要用於跟蹤內容必須在循環的下一次迭代中的大小。我可以在那裏更改代碼,以便不使用框架大小來計算我的內容大小,但是當我編寫代碼時沒有看到選項。 – Arperum 2013-02-27 19:13:27