Skip to content
This repository was archived by the owner on Apr 22, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions class/HPGrowingTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ -(void)setMaxNumberOfLines:(int)n

internalTextView.text = newText;

maxHeight = [self measureHeight];
maxHeight = [internalTextView measureHeight];

internalTextView.text = saveText;
internalTextView.hidden = NO;
Expand Down Expand Up @@ -208,7 +208,7 @@ -(void)setMinNumberOfLines:(int)m

internalTextView.text = newText;

minHeight = [self measureHeight];
minHeight = [internalTextView measureHeight];

internalTextView.text = saveText;
internalTextView.hidden = NO;
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion class/HPTextViewInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
@property (nonatomic, strong) NSString *placeholder;
@property (nonatomic, strong) UIColor *placeholderColor;
@property (nonatomic) BOOL displayPlaceHolder;

- (CGFloat)measureHeight;
@end
20 changes: 16 additions & 4 deletions class/HPTextViewInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ -(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;
self.contentInset = insets;
}
}

// 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];
}

Expand Down Expand Up @@ -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