开发者

UIScrollView: Scrolling doesn't work

I'd like to scroll my content in a UIScrollView. But I think I a made a mistake.

    // 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.sc开发者_StackOverflow社区rollEnabled = YES;
[self.view addSubview:wrapper];

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


Instead of setting large frame you must set UIScrollView's content size:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜