UIScrollView中的UITextView,分页不滚动 [英] UITextView in UIScrollView with paging not scrolling

查看:149
本文介绍了UIScrollView中的UITextView,分页不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have implemented a paging UIScrollView following this excellent tutorial: http://www.iosdevnotes.com/2011/03/uiscrollview-paging/

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

The UIScrollView works like a charm with paging and all. Now, I want to add a UITextView to each of the pages. The TextView should have a fixed size to fit the frame but with scrolling content (if needed). I'm banging my head against the wall because no matter what I try I can't get the textview to scroll! In the main for-loop from the above tutorial I added the following code:

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];

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

I've googled and tested a lot of things but the textview won't scroll. I tested the delaysContentTouches flag, I've locked scrolling directions but it does not change a thing. In another project I tried to do the same and there I got it to scroll on the first page but not on the others?

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

I'm totally lost in space right, hope that anyone out there have the (probably simple) solution.

以下是完整项目的链接:

Here is a link to the complete project:

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

推荐答案

我刚试过这个,它运行正常。

I just tested this and it works fine.

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

In your code, you are adding the text view to the subview. Instead, you should be adding it to the scroll view.

子视图什么都不做,只提供红色。您可以通过调用

The subview does nothing, just provide the red color. You can send it to the back by calling

[self.scrollView bringSubviewToFront:textView];

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

PS: Don't forget to adjust the x of labelFrame to subview.frame.size.width +10. ;-)

这篇关于UIScrollView中的UITextView,分页不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆