我在UIViewController中配置了一个textView,如下所示:textView configuration
但是当控制器viewDidAppear时,我发现UITextView的contentSize = {375, 242}和UITextView不能滚动。
但是如果我点击textView,让textView开始编辑(但什么也不编辑),然后我触摸控制器的视图让textView endEditing,记录textView,这次contentSize = {375, 361}和UITextView可以滚动。有人知道为什么吗?谢谢。
发布于 2016-09-14 13:51:25
你可以添加类似这样的textView,
UITextView *standardTextView = [[UITextView alloc]initWithFrame:CGRectMake(20, 50, self.view.frame.size.width - 40, 120)];
standardTextView.layer.borderWidth = 1.0;
standardTextView.layer.borderColor = [[UIColor lightGrayColor]CGColor];
standardTextView.delegate = self;
standardTextView.font = [UIFont fontWithName:@"Helvetica" size:17.0];
[self.view addSubview:standardTextView];然后,当您的内容(即文本)将大于textview's height时,它将启用滚动,否则将保持禁用状态!!
发布于 2017-01-23 02:31:55
NSTextContainer有一个名为heightTracksTextView的属性,它可能会干扰您在此处的设置,因为默认值为false。
在初始化UITextView和将UITextView添加到视图层次结构之后,我会仔细检查NSTextContainer的高度。
请查看此处的文档:https://developer.apple.com/reference/uikit/nstextcontainer/1444559-heighttrackstextview
如果这不起作用,请告诉我,我知道我以前解决过这个问题,但我现在不在我的电脑前。
https://stackoverflow.com/questions/39482935
复制相似问题