【问题标题】:UITextView is not scrollingUITextView 不滚动
【发布时间】:2012-12-27 09:02:58
【问题描述】:

我想在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];

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

【问题讨论】:

  • ...或者只是删除将userInteractionEnabled 设置为NO 的行。
  • 如果你保留[textview setUserInteractionEnabled:NO];,你认为它会如何运作?您需要将其删除以启用用户交互。
  • 不知道你为什么加了:[textview setUserInteractionEnabled:NO];简单地说,是的。
  • 在这里你设置 UserInterection 是 No 然后在这里没有检测到你的这个 textview 的用户触摸事件所以这个 textview 不会滚动所以只需将它设置为 YES 并且它会工作其他只是评论行 [textview setUserInteractionEnabled:不];或删除此行..

标签: iphone objective-c ios uitextview


【解决方案1】:

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

【讨论】:

  • 并在代码中设置委托 textview.delegate=self;并在您的 .h 文件中添加委托 UITextViewDelegate。
  • 我实现了你们给出的答案。但是,对我没有任何作用。
  • 要么它没有滚动,要么键盘仍然显示..?而且您粘贴的代码也有 [textview setUserInteractionEnabled:NO];您是否将 No 更改为 Yes?
  • 它不滚动,而且键盘也是可见的。我尝试了所有可能的方法。是的,我将其更改为 YES。有什么方法可以启用垂直和水平滚动。
  • 我认为您没有足够的内容来启用滚动。要滚动文本视图,您应该输入非常大的段落,如果段落的内容被隐藏,那么您将能够滚动。
【解决方案2】:

setUserInteractionEnabledUITextView 属性设置YES

设置这条线

[textview setUserInteractionEnabled:YES];

而不是

[textview setUserInteractionEnabled:NO];

【讨论】:

  • @bapirout 嘿伙计在这里你设置 UserInterection 是 No 然后在这里你的这个 textview 的用户触摸事件没有被检测到所以这个 textview 不会滚动所以只需将它设置为 YES 并且它将工作其他只是评论该行[textview setUserInteractionEnabled:NO];或删除此行.. :)
  • @bapirout 它不工作??也先用这个把框架设置小然后试试看,只要给 Rect 像 CGRect frame = CGRectMake(0, 0, 320, 200);试试这个并发表评论..
【解决方案3】:

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

这是我在 Swift 4.0 中所做的:

  1. 非常重要:确保在文本上设置了自动布局 看法。在我的 ViewController 中,我将约束设置为文本视图 到 8,8,8,8 并检查限制到边距。整件事 如果未设置自动布局,则不会滚动。
  2. 这是我使用的代码:

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)

【讨论】:

    【解决方案4】:

    粘贴此代码

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

    【讨论】:

    • 我实现了你们给出的答案。但是,对我没有任何作用。注意:我的文本视图与分段控件绑定。任何段落都将根据所选段可见。
    • @bapirout 将您的父视图属性设置为 clipSubviews = YES,然后检查并告诉我
    【解决方案5】:

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

    [textview setUserInteractionEnabled:NO];
    

    【讨论】:

      【解决方案6】:

      UserInteractionEnabled 设置为YES

      【讨论】:

        【解决方案7】:

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

        【讨论】:

          【解决方案8】:

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

          [textview setUserInteractionEnabled:YES];

          这会对你有所帮助。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2016-08-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-08-23
            相关资源
            最近更新 更多