![](/img/trans.png)
[英]How can a UIView subclass get notified when it has been scrolled by its Superview UIScrollView
[英]adding a UIScrollView as a superview of 2 UITextview made no view can be scrolled
我在viewcontroller中有2个textview。 第一个文本视图不可编辑,但是第二个可编辑。 我想让两个键盘在出现键盘时都滚动到相同的位置和大小。 我想我必须使用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 stil没有滚动...有人知道为什么吗?
验证是否在界面构建器中为第二个textview选中了启用的用户交互。
您为两个文本字段都提供了一些标记值,并且在委托方法中,根据需要执行启用用户交互的操作(false,true)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.