【问题标题】:UITextView Auto Height - Up directionUITextView 自动高度 - 向上方向
【发布时间】:2014-05-06 02:57:19
【问题描述】:

我正在使用此代码制作具有自动调整大小的动态 UITextView

- (void)textViewDidChange:(UITextView *)txtView
{
    CGRect frame;
    frame = txtView.frame;
    frame.size.height = [textView contentSize].height;
    textView.frame = frame;
}

代码很好,但是当我在键盘上按“return”(断线)时,我需要 textView 向上增长,而不是像现在这样向下。

我尝试使用“CGRectGetMaxY(textView.frame)”做一些事情,因为我知道 textView 的底部需要保持不变,但我没有找到正确的方法。

这个textView是用来输出聊天消息的,所以如果用户写的东西很长,textView需要长大,因为键盘在下面

【问题讨论】:

    标签: ios objective-c uitextview


    【解决方案1】:

    这应该可以解决问题:

    - (void)textViewDidChange:(UITextView *)textView
    {
        CGRect frame = textView.frame;
        frame.origin.y = CGRectGetMaxY(frame) - [textView contentSize].height;
        frame.size.height = [textView contentSize].height;
        textView.frame = frame;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 2011-09-16
      • 2011-06-20
      • 2013-09-18
      • 1970-01-01
      相关资源
      最近更新 更多