【问题标题】:adding a UIScrollView as a superview of 2 UITextview made no view can be scrolled添加一个 UIScrollView 作为 2 UITextview 的超级视图使视图无法滚动
【发布时间】: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


    【解决方案1】:

    验证是否在第二个文本视图的界面构建器中选中了启用的用户交互。

    【讨论】:

    • 如果我想让第一个文本视图不可编辑而第二个文本视图可编辑怎么办?有什么建议吗?
    • 我尝试使用 xib 中的 Embed Object In,例如本页 stackoverflow.com/questions/1521308/… 上的示例,但是我的 xib 中的“Embed Object In”无法选择,你知道为什么吗?
    【解决方案2】:

    您为两个文本字段提供一些标记值,并在委托方法中,根据您的需要执行 userinteraction enabled(false,true)。

    【讨论】:

    • 我必须这样做......给每个文本视图一个标签,并将 userinteractionenabled:YES 设置为关闭它们。但只是第二个滚动,第一个仍然没有滚动
    猜你喜欢
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 2011-06-19
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多