From c28ed8bb06e1864b16326ba3f12648879653ccc1 Mon Sep 17 00:00:00 2001 From: Tim Taylor Date: Sat, 5 May 2012 14:43:44 -0700 Subject: [PATCH] Added a method to the protocol to query the delegate on whether or not the growing text view can change sizes. --- class/HPGrowingTextView.h | 1 + class/HPGrowingTextView.m | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/class/HPGrowingTextView.h b/class/HPGrowingTextView.h index 8311a41..da2aaa5 100644 --- a/class/HPGrowingTextView.h +++ b/class/HPGrowingTextView.h @@ -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; diff --git a/class/HPGrowingTextView.m b/class/HPGrowingTextView.m index 1493f7a..de2c171 100644 --- a/class/HPGrowingTextView.m +++ b/class/HPGrowingTextView.m @@ -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