我有一堆“行视图”,我想放在一个垂直滚动视图。我在IB中创建了一个单独的nib行视图。它们的大小是1024/200(ipad)。现在我想把它们一个接一个地放到我的父UIScrollView中。我尝试了一个简单的方法ubview:rowView]但这会使它们相互重叠(为了检查这一点,我将rowview设置为透明的)。因此,我开始愚弄每个行视图的边界,但没有结果。这是我的密码。注意“self.yextensofar”被初始化为0。想象一下为每一行调用下面的代码:
MyRowView *rowView = [[MyRowView alloc] init];
float calculatedWidth = 0;
// minus nav bar
float calculatedHeight = 0;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIInterfaceOrientationPortrait){
// iPad
calculatedWidth = 768.0;
calculatedHeight = 960.0;
}else{
// iPad
calculatedWidth = 1024.0;
calculatedHeight = 704.0;
}
[self.vScroll addSubview: rowView.view];
[rowView.view setBounds:CGRectMake(0, self.yExtentSoFar, calculatedWidth,200)];
[self.vScroll setContentSize:CGSizeMake(calculatedWidth, yExtentSoFar+200)];
self.yExtentSoFar += 200;
因此,在我尝试设置边界之前,行视图似乎彼此重叠。我想可以理解。当我设置边界时,第二行视图并没有像预期的那样出现在第一行下面,相反,我必须下拉vScroll,第二行视图出现在第一个屏幕外的上面!
有人能指出我错在哪里吗?谢谢,