Skip to content
This repository has been archived by the owner on Apr 22, 2019. It is now read-only.

Added a protocol method to query delegate about growing the text view #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions class/HPGrowingTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height;
- (void)growingTextView:(HPGrowingTextView *)growingTextView didChangeHeight:(float)height;
- (BOOL)growingTextViewCanChangeHeight:(HPGrowingTextView *)growingTextView;

- (void)growingTextViewDidChangeSelection:(HPGrowingTextView *)growingTextView;
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView;
Expand Down
30 changes: 19 additions & 11 deletions class/HPGrowingTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,27 @@ - (void)textViewDidChange:(UITextView *)textView

-(void)resizeTextView:(NSInteger)newSizeH
{
if ([delegate respondsToSelector:@selector(growingTextView:willChangeHeight:)]) {
[delegate growingTextView:self willChangeHeight:newSizeH];
BOOL canChangeHeight=YES;
if ([delegate respondsToSelector:@selector(growingTextViewCanChangeHeight:)]) {
canChangeHeight=[delegate growingTextViewCanChangeHeight:self];
}

CGRect internalTextViewFrame = self.frame;
internalTextViewFrame.size.height = newSizeH; // + padding
self.frame = internalTextViewFrame;

internalTextViewFrame.origin.y = contentInset.top - contentInset.bottom;
internalTextViewFrame.origin.x = contentInset.left;
internalTextViewFrame.size.width = internalTextView.contentSize.width;

internalTextView.frame = internalTextViewFrame;
if (canChangeHeight) {
if ([delegate respondsToSelector:@selector(growingTextView:willChangeHeight:)]) {
[delegate growingTextView:self willChangeHeight:newSizeH];
}

CGRect internalTextViewFrame = self.frame;
internalTextViewFrame.size.height = newSizeH; // + padding
self.frame = internalTextViewFrame;

internalTextViewFrame.origin.y = contentInset.top - contentInset.bottom;
internalTextViewFrame.origin.x = contentInset.left;
internalTextViewFrame.size.width = internalTextView.contentSize.width;

internalTextView.frame = internalTextViewFrame;
}

}

-(void)growDidStop
Expand Down