UIScrollView setContentSize 是如何工作的
How UIScrollView setContentSize works
ContentSize
是 UIScrollView
的 property
。在我的 UITableView
子类中我实现了这个
- (void)setContentSize:(CGSize)contentSize {
NSLog(@"contentSize = %f, %f", contentSize.width, contentSize.height);
NSLog(@"self.contentSize = %f, %f", self.contentSize.width, self.contentSize.height);
}
这个contentSize
是从哪里来的?为什么 contentSize
和 self.contentSize
有不同的值?
它来自 table 视图委托,当它提供部分和行数以及行高时。
值不同,因为一个是现有大小,一个是新计算的大小,只要您要求 table 重新加载数据/添加/删除行或部分,就会发生这种情况。
contentSize
是方法 setContentSize:
的参数。此方法覆盖 setContentSize:
,因此它接受内容大小的新值。如果你想记录它并让它正常工作,你还需要添加行 super.contentSize = contentSize;
.
ContentSize
是 UIScrollView
的 property
。在我的 UITableView
子类中我实现了这个
- (void)setContentSize:(CGSize)contentSize {
NSLog(@"contentSize = %f, %f", contentSize.width, contentSize.height);
NSLog(@"self.contentSize = %f, %f", self.contentSize.width, self.contentSize.height);
}
这个contentSize
是从哪里来的?为什么 contentSize
和 self.contentSize
有不同的值?
它来自 table 视图委托,当它提供部分和行数以及行高时。
值不同,因为一个是现有大小,一个是新计算的大小,只要您要求 table 重新加载数据/添加/删除行或部分,就会发生这种情况。
contentSize
是方法 setContentSize:
的参数。此方法覆盖 setContentSize:
,因此它接受内容大小的新值。如果你想记录它并让它正常工作,你还需要添加行 super.contentSize = contentSize;
.