简体   繁体   中英

adding a UIScrollView as a superview of 2 UITextview made no view can be scrolled

i have 2 textview in a viewcontroller. the 1st textview is not editable, but the 2nd is editable. i want to make both of them scroll in the same position and size when the keyboard is appear. I think i have to use UIScrollView as base of both of textview. And then i add the UIScrollView in xib (bot of textview are made in xib too). and this is the picture if this hierarchy :

替代文字

in the viewDidLoad method, i add this code :

- (void)viewDidLoad {
[super viewDidLoad];

[scrollTextView addSubview:lineNumberTextView];
[scrollTextView addSubview:_codeTextView];

[lineNumberTextView bringSubviewToFront:scrollTextView];
[_codeTextView bringSubviewToFront:scrollTextView];

}

but after that i can't scroll anything. What i have to do? thx for the advices

UPDATE

this my code after do some advises like mac gave to me :

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

}

but just the _codeTextView scroll, the lineTextVew stil didn't scroll...somebody know why??

验证是否在界面构建器中为第二个textview选中了启​​用的用户交互。

您为两个文本字段都提供了一些标记值,并且在委托方法中,根据需要执行启用用户交互的操作(false,true)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM