UITextView不滚动
我想在UITextView
显示一个段落。 我能够在文本视图中放置段落的内容,但我无法滚动UITextView
(由于它不滚动,一些内容不可见)。
我想要做的是:
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];
在这种情况下,启用滚动。 任何人都可以告诉我它为什么不滚动?
set [textview setUserInteractionEnabled:TRUE];
并且我认为你不想弹出键盘然后你可以通过实现uitextview委托方法隐藏键盘-(void)textViewDidBeginEditing:(UITextView *)textView{[textView resignFirstResponder];
为UITextView
setUserInteractionEnabled
属性设置YES
设置这一行
[textview setUserInteractionEnabled:YES];
代替
[textview setUserInteractionEnabled:NO];
粘贴此代码
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];
添加以下行: [textview setUserInteractionEnabled:YES];
代替这个:
[textview setUserInteractionEnabled:NO];
将UserInteractionEnabled
设置为YES
。
我有一个ViewController只有一个文本视图,大约有5页文本。
这是我在Swift 4.0中所做的:
- 非常重要:确保在文本视图中设置了自动布局。 在我的ViewController中,我将约束条件设置为文本视图为8,8,8,8,并对边距进行了约束检查。 如果未设置自动布局,则整个事件不会滚动。
- 这是我使用的代码:
Swift 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)
我有同样的问题,我有setscrollable和userinteractionenabled为TRUE。 事实certificate这是一个约束问题。 要解决此问题,请单击故事板中的视图控制器(右上角的电池图标),然后转到“编辑器” – >“解决自动布局问题” – >“添加缺失约束”。 修复了我的问题!
bapi rout,有一个用户与textView交互的属性。 您已将其设置为否。如果要在TextView上执行滚动,则必须启用此属性。
[textview setUserInteractionEnabled:YES];
这对你有所帮助。