Skip to content

修复IOS8系统输入之后不上移的问题,直接用如下代码代码替换即可 #5

@simayang01

Description

@simayang01
- (void)textDidChange
{
    self.placeholderView.hidden = self.text.length > 0;
    NSInteger height = ceilf([self sizeThatFits:CGSizeMake(self.bounds.size.width, MAXFLOAT)].height);
    if (_textH != height) {
        self.scrollEnabled = height > _maxTextH && _maxTextH > 0;
        if (self.scrollEnabled) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                self.layoutManager.allowsNonContiguousLayout = false;
                self.contentSize = [self sizeThatFits:CGSizeMake(self.bounds.size.width, MAXFLOAT)];
                [self setContentOffset:CGPointMake(0, self.contentSize.height - self.bounds.size.height) animated:NO];
                
                CGFloat cursorPosition;
                if (self.selectedTextRange) {
                    cursorPosition = [self caretRectForPosition:self.selectedTextRange.start].origin.y;
                } else {
                    cursorPosition = 0;
                }
                float _minTextH = ceil(self.font.lineHeight * 1 + self.textContainerInset.top + self.textContainerInset.bottom);
                CGRect cursorRowFrame = CGRectMake(0, cursorPosition - _minTextH, self.bounds.size.width, _minTextH);
                CGRect textViewFrame = [self convertRect:cursorRowFrame fromView:self];
                [self scrollRectToVisible:textViewFrame animated:NO];
                [self layoutIfNeeded];
            });
        }
        
        _textH = height;
        if (_yz_textHeightChangeBlock && self.scrollEnabled == NO) {
            _yz_textHeightChangeBlock(self.text,height);
            [self.superview layoutIfNeeded];
            self.placeholderView.frame = self.bounds;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions