ios UITextView 不滚动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14051992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:38:26  来源:igfitidea点击:

UITextView is not scrolling

iphoneobjective-ciosuitextview

提问by bapi

I want to display one paragraph in UITextView. I'm able to put the content of paragraph in Text view, but I'm unable to scroll UITextView(Some of the content is not visible as it's not scrolling).

我想在UITextView. 我可以将段落的内容放在文本视图中,但无法滚动UITextView(部分内容不可见,因为它没有滚动)。

What I'm trying to do is:

我想要做的是:

CGRect frame = CGRectMake(0, 0, 320, 480);
//allocate view
self.view = [[UIView alloc]initWithFrame:frame];textview = [[UITextView alloc]initWithFrame:CGRectMake(30, 200, 275, 400)];
[textview setFont:[UIFont fontWithName:@"Arial" size:12]];
[textview setScrollEnabled:YES];
[textview setUserInteractionEnabled:NO];
[textview setBackgroundColor:[UIColor clearColor]];
//[textview setText:@"Hi,I'm working fine with this space"];
[self.view addSubview:textview];

In this case, scrolling is enabled. Can any one tell me why it's not scrolling?

在这种情况下,启用滚动。谁能告诉我为什么它不滚动?

回答by Ahsan

set [textview setUserInteractionEnabled:TRUE];and I think you dont want to keyboard to pop up then you can hide the keyboard by implementing the uitextview delegate methode -(void)textViewDidBeginEditing:(UITextView *)textView{[textView resignFirstResponder];

设置[textview setUserInteractionEnabled:TRUE];,我认为您不想弹出键盘,然后您可以通过实现 uitextview 委托方法来隐藏键盘-(void)textViewDidBeginEditing:(UITextView *)textView{[textView resignFirstResponder];

回答by Paras Joshi

set YESfor setUserInteractionEnabledproperty of UITextView

设置YESsetUserInteractionEnabled属性UITextView

set this line

设置这条线

[textview setUserInteractionEnabled:YES];

instead of

代替

[textview setUserInteractionEnabled:NO];

回答by D. Rothschild

I have a ViewController that only has a text view with about 5 pages of text.

我有一个 ViewController,它只有一个包含大约 5 页文本的文本视图。

Here is what I did in Swift 4.0:

这是我在 Swift 4.0 中所做的:

  1. Very important: Make sure you have auto layout set on the text view. In my ViewController, I set my constraints to the text view to 8,8,8,8 with constrain to margins checked. The whole thing does not scroll if auto layout is not set.
  2. This is the code I used:
  1. 非常重要:确保您在文本视图上设置了自动布局。在我的 ViewController 中,我将文本视图的约束设置为 8,8,8,8,并检查了对边距的约束。如果未设置自动布局,则整个内容不会滚动。
  2. 这是我使用的代码:

Swift 4.0

斯威夫特 4.0

textForPrivacyPolicy.showsVerticalScrollIndicator = true
textForPrivacyPolicy.isEditable = false
textForPrivacyPolicy.isScrollEnabled = true
textForPrivacyPolicy.scrollRangeToVisible(NSMakeRange(0, 0))
textForPrivacyPolicy.setContentOffset(CGPoint(x: 0, y: 0), animated: false)

回答by Nikita P

Set UserInteractionEnabledas YES.

设置UserInteractionEnabledYES

回答by Vishal

Add this line : [textview setUserInteractionEnabled:YES];in place of this:

添加这一行:[textview setUserInteractionEnabled:YES];代替这一行:

[textview setUserInteractionEnabled:NO];

回答by P.J

Paste this code

粘贴此代码

CGRect frame = CGRectMake(0, 0, 320, 480);
//allocate view
self.view = [[UIView alloc]initWithFrame:frame];textview = [[UITextView alloc]initWithFrame:CGRectMake(30, 200, 275, 400)];
[textview setFont:[UIFont fontWithName:@"Arial" size:12]];
[textview setScrollEnabled:YES];
[textview setUserInteractionEnabled:YES];
[textview setBackgroundColor:[UIColor clearColor]];
//[textview setText:@"Hi,I'm working fine with this space"];
[self.view addSubview:textview];

回答by Rahul

I had the same issue and I had setscrollable and userinteractionenabled to TRUE. It turned out to be a problem with Constraints. In order to fix this, click on your view controller in ur storyboard (the battery icon on top right), then go to "Editor"->"Resolve Auto Layout Issues"->"Add Missing Constraints In ". Fixed the issue for me!

我遇到了同样的问题,我将 setscrollable 和 userinteractionenabled 设置为 TRUE。结果证明是约束的问题。为了解决这个问题,在你的故事板中点击你的视图控制器(右上角的电池图标),然后转到“编辑器”->“解决自动布局问题”->“添加缺少的约束”。为我解决了这个问题!

回答by Ashu

bapi rout , There is a property for the user interaction with textView. You have set it to No. If you want to perform scroll on TextView, You have to enable this property.

bapi rout ,有一个用户与 textView 交互的属性。您已将其设置为 No。如果您想在 TextView 上执行滚动,您必须启用此属性。

[textview setUserInteractionEnabled:YES];

[textview setUserInteractionEnabled:YES];

This will help you.

这会帮助你。