【问题标题】:How to implement scrolling functionality in UITextView?如何在 UITextView 中实现滚动功能?
【发布时间】:2012-11-21 06:32:15
【问题描述】:

我正在使用 UITextView,如果文本在键盘下方展开,则它根本无法滚动,如下图所示。因此,如果文本与键盘对齐或在键盘下方,我需要某种滚动来向下滚动视图。我一直在寻找类似的示例/教程,但没有找到任何适合我的项目的好示例。

我将在下面的 .h 文件中发布我是如何实现 UITextView* commentField 的。从这里我该怎么办?如果您可以具体使用示例代码,我们将不胜感激! /问候

http://tinypic.com/view.php?pic=kck6t&s=6

ReportViewController.h 文件:

@interface ReportViewController : MLUIViewController <MLReportErrorDelegate, UITextFieldDelegate, UIGestureRecognizerDelegate>
{

IBOutlet UITextView *commentField;
IBOutlet UITextField *emailField;

}

@property (nonatomic, retain) UITextView *commentField;

ReportViewController.m 文件:

- (void) textViewShouldBeginEditing:(UITextView *)commentField
{
???????????????????????
}

【问题讨论】:

    标签: ios uiscrollview keyboard scroll uitextview


    【解决方案1】:

    您需要在输入时将 textView 设置为完全可见。我认为当文本位于键盘下方时,您无法动态滚动。

    您可以使用以下代码来完成。

    //—-resize the scroll view (with keyboard)—-
    CGRect viewFrame = [scrollView frame];
    viewFrame.size.height -= keyboardRect.size.height;
    scrollView.frame = viewFrame;
    
    //—-scroll to the current text field—-
    CGRect textFieldRect = [yourTextView frame];
    [scrollView scrollRectToVisible:textFieldRect animated:YES];
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-13
        • 1970-01-01
        • 2021-12-19
        • 2014-11-10
        • 1970-01-01
        相关资源
        最近更新 更多