UITextView插入行为iOS 7与iOS 8

UITextView插入行为iOS 7与iOS 8,ios,objective-c,uitextview,Ios,Objective C,Uitextview,我有一个UITextView,它在iOS 7中运行良好。在iOS 8中,它的行为很奇怪 当我输入变为两行的文本时,我会更新包含textview的inputView的大小。我还更新了文本视图的大小,但不知怎的,它似乎滚动掉了第一行;但这并没有反映在它的规模上 iOS 7中的行为视频(正确): iOS 8中的行为视频: 我已经设置了[自设置自动调整滚动视图插图:否],但没有更改。 这对我没有帮助: iOS8中的myNSLog有以下结果: 2014-12-22 02:02:48.104 Date

我有一个
UITextView
,它在iOS 7中运行良好。在iOS 8中,它的行为很奇怪

当我输入变为两行的文本时,我会更新包含textview的inputView的大小。我还更新了文本视图的大小,但不知怎的,它似乎滚动掉了第一行;但这并没有反映在它的规模上

iOS 7中的行为视频(正确):

iOS 8中的行为视频:

我已经设置了
[自设置自动调整滚动视图插图:否],但没有更改。
这对我没有帮助:

iOS8中的my
NSLog
有以下结果:

2014-12-22 02:02:48.104 Date For Date[68577:10129965] DID BEGIN: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:50.579 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:50.768 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:50.960 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:51.168 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:52.145 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
2014-12-22 02:02:52.408 Date For Date[68577:10129965] DID CHANGE: textContainerInset Top: 8.000000 - contentInset Bottom: 0.000000 - scrollIndicatorInset: 10.000000
这是我的代码:

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    [textView becomeFirstResponder];

    if(!self.previousTextViewContentHeight)
        self.previousTextViewContentHeight = textView.contentSize.height;

    [self _scrollToBottom:YES];

    NSLog(@"DID BEGIN: textContainerInset Top: %f - contentInset Bottom: %f - scrollIndicatorInset: %f", textView.textContainerInset.top, textView.contentInset.top, textView.scrollIndicatorInsets.top);
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    [textView resignFirstResponder];
}

- (void)textViewDidChange:(UITextView *)textView
{
    // Textfield
    NSLog(@"DID CHANGE: textContainerInset Top: %f - contentInset Bottom: %f - scrollIndicatorInset: %f", textView.textContainerInset.top, textView.contentInset.top, textView.scrollIndicatorInsets.top);

    CGFloat maxHeight = [JSMessageInputView maxHeight];
    CGFloat textViewContentHeight = MIN(textView.contentSize.height, maxHeight);

    CGFloat changeInHeight = textViewContentHeight - self.previousTextViewContentHeight;

    self.previousTextViewContentHeight = MIN(textViewContentHeight, maxHeight);

    if(changeInHeight != 0.0f) {
        textView.frame = CGRectMake(6, 3, textView.frame.size.width, textView.frame.size.height + changeInHeight);

        textView.contentInset = UIEdgeInsetsMake(0.0f,
                                                 0.0f,
                                                 0.0f,
                                                 0.0f);

        [textView setContentSize:CGSizeMake(textView.contentSize.width, textView.contentSize.height + changeInHeight)];

        // Change table
        UIEdgeInsets insets = UIEdgeInsetsMake(0, 0.0f, self.bubbleTable.contentInset.bottom + changeInHeight, 0.0f);
        self.bubbleTable.contentInset = insets;
        self.bubbleTable.scrollIndicatorInsets = insets;

        [self _scrollToBottom:YES];

        // Change input view
        CGRect inputViewFrame = self.inputView.frame;
        self.inputView.frame = CGRectMake(0.0f,
                                          inputViewFrame.origin.y - changeInHeight,
                                          inputViewFrame.size.width,
                                          inputViewFrame.size.height + changeInHeight);
    }

    self.inputView.sendButton.enabled = ([textView.text trimWhitespace].length > 0);
}

我做错了什么?

为什么不使用
UITextView
sizeThatFits
函数?它将自动计算所有填充的正确高度:

CGFloat textViewHeight = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, MAXFLOAT)].height;

尝试
textView.textContainer.lineFragmentPadding=0textView.textContainerInset=UIEdgeInsetsZero。这使我的文字接近UITextView的边界。

请附上一个示例项目。暂时还没有,只要我找到时间。。。我来做一个。对不起的:(你有一个悬赏打开。我想帮忙。我看到了一个有趣的显示类似于此的东西。你能在同一个手机模拟器上记录textview.frame.size.width并比较iOS 7和iOS 8吗。我有一个预感,iOS 8的宽度将小于iOS 7的宽度,因此所有的文本计算都将关闭。请检查I。)这可能会帮助你:这解决了我的大部分问题。我会更新我的问题,告诉你到底是什么解决了我的问题。谢谢!