0

在我看来控制器的viewDidLoad功能,我有这个人:

UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:self.view.frame];
scroller.contentSize = self.view.frame.size; // Tried w/ and w/o this
scroller.showsVerticalScrollIndicator = YES; // Tried w/ and w/o this

for (int x = 0; x < 10; x++) {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, x * 100, 100, 100)];
    label.text = [NSString stringWithFormat:@"%i label", x];
    [scroller addSubview:label];
}

[self.view addSubview:scroller];

它显示前 8 个标签 OK,但滚动视图不会...滚动。它只是被切断了。知道为什么吗?

4

1 回答 1

0

它不会滚动,因为您contentSize仅设置为与滚动视图本身相同的大小。这contentSize是滚动视图充当窗口的可滚动区域的大小。您需要将其设置得足够宽才能真正看到您的标签。

根据您当前的代码,您的最终标签为 rect {0, 900, 100, 100},因此您contentSize至少需要为CGSizeMake(100, 1000).

于 2012-08-30T00:04:47.903 回答