diff --git a/class/HPGrowingTextView.m b/class/HPGrowingTextView.m index 9871c6f..01e2606 100644 --- a/class/HPGrowingTextView.m +++ b/class/HPGrowingTextView.m @@ -171,7 +171,7 @@ -(void)setMaxNumberOfLines:(int)n internalTextView.text = newText; - maxHeight = [self measureHeight]; + maxHeight = [internalTextView measureHeight]; internalTextView.text = saveText; internalTextView.hidden = NO; @@ -208,7 +208,7 @@ -(void)setMinNumberOfLines:(int)m internalTextView.text = newText; - minHeight = [self measureHeight]; + minHeight = [internalTextView measureHeight]; internalTextView.text = saveText; internalTextView.hidden = NO; @@ -259,7 +259,7 @@ - (void)textViewDidChange:(UITextView *)textView - (void)refreshHeight { //size of content, so we can set the frame of self - NSInteger newSizeH = [self measureHeight]; + NSInteger newSizeH = [internalTextView measureHeight]; if (newSizeH < minHeight || !internalTextView.hasText) { newSizeH = minHeight; //not smalles than minHeight } @@ -346,18 +346,6 @@ - (void)refreshHeight } } -// Code from apple developer forum - @Steve Krulewitz, @Mark Marszal, @Eric Silverberg -- (CGFloat)measureHeight -{ - if ([self respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)]) - { - return ceilf([self.internalTextView sizeThatFits:self.internalTextView.frame.size].height); - } - else { - return self.internalTextView.contentSize.height; - } -} - - (void)resetScrollPositionForIOS7 { CGRect r = [internalTextView caretRectForPosition:internalTextView.selectedTextRange.end]; diff --git a/class/HPTextViewInternal.h b/class/HPTextViewInternal.h index 175f4d4..76adfbe 100644 --- a/class/HPTextViewInternal.h +++ b/class/HPTextViewInternal.h @@ -33,5 +33,5 @@ @property (nonatomic, strong) NSString *placeholder; @property (nonatomic, strong) UIColor *placeholderColor; @property (nonatomic) BOOL displayPlaceHolder; - +- (CGFloat)measureHeight; @end diff --git a/class/HPTextViewInternal.m b/class/HPTextViewInternal.m index f3a6a1d..c06c839 100644 --- a/class/HPTextViewInternal.m +++ b/class/HPTextViewInternal.m @@ -59,7 +59,7 @@ -(void)setContentOffset:(CGPoint)s } else { float bottomOffset = (self.contentSize.height - self.frame.size.height + self.contentInset.bottom); - if(s.y < bottomOffset && self.scrollEnabled){ + if(s.y <= bottomOffset && self.scrollEnabled){ UIEdgeInsets insets = self.contentInset; insets.bottom = 8; insets.top = 0; @@ -67,10 +67,10 @@ -(void)setContentOffset:(CGPoint)s } } - // Fix "overscrolling" bug - if (s.y > self.contentSize.height - self.frame.size.height && !self.decelerating && !self.tracking && !self.dragging) + // Fix "overscrolling" bug + fix the "Chinese character input" bug + if (!self.decelerating && !self.tracking && !self.dragging){ s = CGPointMake(s.x, self.contentSize.height - self.frame.size.height); - + } [super setContentOffset:s]; } @@ -123,4 +123,16 @@ -(void)setPlaceholder:(NSString *)placeholder [self setNeedsDisplay]; } +// Code from apple developer forum - @Steve Krulewitz, @Mark Marszal, @Eric Silverberg +- (CGFloat)measureHeight +{ + if ([self respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)]) + { + return ceilf([self sizeThatFits:self.frame.size].height); + } + else { + return self.contentSize.height; + } +} + @end