【发布时间】:2010-12-27 03:46:57
【问题描述】:
我在视图控制器中有 2 个文本视图。第一个文本视图不可编辑,但第二个是可编辑的。我想让它们在键盘出现时滚动到相同的位置和大小。我想我必须使用 UIScrollView 作为两个 textview 的基础。然后我在 xib 中添加 UIScrollView(textview 的机器人也是在 xib 中制作的)。这就是这个层次结构的图片:
在 viewDidLoad 方法中,我添加了这段代码:
- (void)viewDidLoad {
[super viewDidLoad];
[scrollTextView addSubview:lineNumberTextView];
[scrollTextView addSubview:_codeTextView];
[lineNumberTextView bringSubviewToFront:scrollTextView];
[_codeTextView bringSubviewToFront:scrollTextView];
}
但在那之后我不能滚动任何东西。我必须做什么? 谢谢你的建议
更新
这是我的代码在做了一些类似 mac 给我的建议之后:
- (void)viewDidLoad {
[super viewDidLoad];
scrollTextView.showsVerticalScrollIndicator = YES;
scrollTextView.showsHorizontalScrollIndicator = YES;
scrollTextView.scrollEnabled = YES;
_codeTextView.showsHorizontalScrollIndicator = NO;
_codeTextView.showsVerticalScrollIndicator = NO;
_codeTextView.scrollEnabled = YES;
_codeTextView.tag = 0;
_codeTextView.delegate = self;
lineNumberTextView.showsVerticalScrollIndicator = NO;
lineNumberTextView.showsHorizontalScrollIndicator = NO;
lineNumberTextView.scrollEnabled = YES;
lineNumberTextView.tag = 1;
lineNumberTextView.delegate = self;
}
但只是 _codeTextView 滚动,lineTextVew 仍然没有滚动...有人知道为什么吗??
【问题讨论】:
标签: iphone uiscrollview uitextview