UIScrollView:滚动不起作用

时间:2010-02-16 11:53:09

标签: iphone uiscrollview

我想在UIScrollView中滚动我的内容。但我认为我犯了一个错误。

    // setup view
CGRect appFrame = [UIScreen mainScreen].applicationFrame;
CGRect frame = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height);
self.view = [[[UIView alloc] initWithFrame:frame] autorelease];

// setup wrapper
UIScrollView *wrapper = [[UIScrollView  alloc] initWithFrame:CGRectMake(0, 0, appFrame.size.width, appFrame.size.height + 320)];
wrapper.backgroundColor = [UIColor redColor];
wrapper.scrollEnabled = YES;
[self.view addSubview:wrapper];

// title (simple version here)
title.text = "Hello World";
[wrapper addSubview:title];

1 个答案:

答案 0 :(得分:7)

您必须设置UIScrollView的内容大小,而不是设置大框架:

UIScrollView *wrapper = [[UIScrollView  alloc] initWithFrame:
             CGRectMake(0, 0, appFrame.size.width, appFrame.size.height)];
wrapper.contentSize =CGSizeMake(appFrame.size.width, appFrame.size.height + 320);