UITextView,在编辑时滚动? [英] UITextView, scroll while editing?

查看:123
本文介绍了UITextView,在编辑时滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的 UITextView ,几乎全屏。如果我点击它,键盘弹出,我可以编辑文本。然而,我输入的时间越长,最终文本在视图中运行,在键盘后面。我不能再看到我在输入什么。

I've got a big UITextView, nearly full screen. If I tap it, the keyboard pops up and I can edit the text. However, the longer I type, eventually the text runs down the view, behind the keyboard. I can no longer see what I'm typing.

您如何处理这个问题?你必须跟踪光标位置并手动滚动视图吗?

How do you deal with this? Do you have to track the cursor position and scroll the view manually?

推荐答案

我想你必须调整你的UITextView作为键盘显示/隐藏。所以键盘不会超过你的textview。这是示例代码。

I guess you have to size your UITextView as keyboard shows/hides. So the keyboard won't be over your textview. Here is the sample codes.

- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}

- (void)keyboardWillShow:(NSNotification *)notification
{
    [UIView beginAnimations:nil context:nil];
    CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGRect newRect = YOUT_TEXT_VIEW.frame;
    //Down size your text view
    newRect.size.height -= endRect.size.height;
    YOUT_TEXT_VIEW.frame = newRect;
    [UIView commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    ... // Resize your textview when keyboard is going to hide
}

这篇关于UITextView,在编辑时滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆