1

我已经UIScrollView按照这个优秀的教程实现了分页:http: //www.iosdevnotes.com/2011/03/uiscrollview-paging/

这些UIScrollView作品就像一个带有分页和所有功能的魅力。现在,我想为UITextView每个页面添加一个。应该有一个固定的TextView大小以适应框架但带有滚动内容(如果需要)。我正在用头撞墙,因为无论我尝试什么,我都无法让 textview 滚动!在上述教程的主 for 循环中,我添加了以下代码:

CGRect labelFrame;
UITextView *textView;

labelFrame.size.width = scrollView.frame.size.width-24;
labelFrame.size.height = scrollView.frame.size.height-48;
labelFrame.origin.x = 10;
labelFrame.origin.y = 40;

textView = [[UITextView alloc] initWithFrame:labelFrame];
textView.textColor = [UIColor blackColor];
textView.backgroundColor = [UIColor redColor];
textView.font = [UIFont systemFontOfSize:13];
textView.text = @"a very long text";

textView.editable = NO;
textView.scrollEnabled = YES;
textView.userInteractionEnabled = YES;
textView.delegate = self;
textView.contentSize = CGSizeMake(1, 1000); //this would make it scroll?
[subview addSubview:textView];

我已经用谷歌搜索并测试了很多东西,但 textview 不会滚动。我测试了delaysContentTouches标志,我已经锁定了滚动方向,但它并没有改变任何东西。在另一个项目中,我尝试做同样的事情,我让它在第一页上滚动,而不是在其他页面上滚动?

我完全迷失在太空中,希望那里的任何人都有(可能很简单)的解决方案。

这是完整项目的链接:

https://dl.dropbox.com/u/7312515/mycode.zip

4

1 回答 1

1

我刚刚对此进行了测试,它工作正常。

在您的代码中,您将文本视图添加到subview. 相反,您应该将其添加到滚动视图中。

子视图什么都不做,只提供红色。您可以通过调用将其发送到后面

[self.scrollView bringSubviewToFront:textView];

PS:别忘了x调整labelFrameto subview.frame.size.width +10。;-)

于 2012-10-13T23:24:03.177 回答