From 603a505ce532f5299b981c60ab6e8bbcfdecce5e Mon Sep 17 00:00:00 2001 From: taijizhu Date: Tue, 31 Mar 2015 07:51:31 +0800 Subject: [PATCH 1/3] Add block support to dismiss --- Classes/YIPopupTextView.m | 41 +++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/Classes/YIPopupTextView.m b/Classes/YIPopupTextView.m index 7952e22..6df0cca 100644 --- a/Classes/YIPopupTextView.m +++ b/Classes/YIPopupTextView.m @@ -243,11 +243,7 @@ - (id)initWithPlaceHolder:(NSString*)placeHolder if (maxCount > 0) { _countLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _countLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin; -#if (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_6_0) - _countLabel.textAlignment = UITextAlignmentRight; -#else - _countLabel.textAlignment = NSTextAlignmentRight; -#endif + _countLabel.textAlignment = UITextAlignmentRight; _countLabel.backgroundColor = [UIColor clearColor]; _countLabel.textColor = [UIColor lightGrayColor]; _countLabel.font = [UIFont boldSystemFontOfSize:COUNT_SIZE]; @@ -396,7 +392,7 @@ - (void)showInView:(UIView*)view else { targetView = view; frame = view.bounds; - } + } _backgroundView.alpha = 0; _backgroundView.frame = frame; @@ -454,6 +450,9 @@ - (void)dismissWithCancelled:(BOOL)cancelled [self.delegate popupTextView:self willDismissWithText:self.text cancelled:cancelled]; } + if (self.willDismiss) + self.willDismiss(self,self.text,cancelled); + [UIView animateWithDuration:ANIMATION_DURATION animations:^{ _backgroundView.alpha = 0; @@ -465,6 +464,9 @@ - (void)dismissWithCancelled:(BOOL)cancelled [self.delegate popupTextView:self didDismissWithText:self.text cancelled:cancelled]; } + if (self.didDismiss) + self.didDismiss(self,self.text,cancelled); + [_backgroundView removeFromSuperview]; _backgroundView = nil; _popupView = nil; @@ -599,8 +601,12 @@ - (void)_changePopupViewFrameWithNotification:(NSNotification*)notification popupViewHeight = MIN(popupViewHeight, _backgroundView.bounds.size.height-topMargin-bottomMargin); CGRect frame = _backgroundView.bounds; - frame.origin.y = topMargin; - frame.size.height = popupViewHeight; + + if (!IS_IPAD) + { + frame.origin.y = topMargin; + frame.size.height = popupViewHeight; + } _popupView.frame = frame; } @@ -619,7 +625,7 @@ - (void)onTextDidChangeNotification:(NSNotification*)notification - (void)updateCount { NSUInteger textCount = [self.text length]; - _countLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)_maxCount-textCount]; + _countLabel.text = [NSString stringWithFormat:@"%d", _maxCount-textCount]; if (_maxCount > 0 && textCount > _maxCount) { _acceptButton.enabled = NO; @@ -642,23 +648,12 @@ - (void)updateCount - (void)handleCloseButton:(UIButton*)sender { - [self _handleButtonWithCancelled:YES]; + [self dismissWithCancelled:YES]; } - (void)handleAcceptButton:(UIButton*)sender { - [self _handleButtonWithCancelled:NO]; -} - -- (void)_handleButtonWithCancelled:(BOOL)cancelled -{ - if ([self.delegate respondsToSelector:@selector(popupTextView:shouldDismissWithText:cancelled:)]) { - if (![self.delegate popupTextView:self shouldDismissWithText:self.text cancelled:cancelled]) { - return; - } - } - - [self dismissWithCancelled:cancelled]; + [self dismissWithCancelled:NO]; } #pragma mark @@ -780,4 +775,4 @@ - (void)shiftCaret self.selectedRange = range; } -@end \ No newline at end of file +@end From fdbde41bb52761594a38f0e1fb73a765f0e4c744 Mon Sep 17 00:00:00 2001 From: taijizhu Date: Tue, 31 Mar 2015 07:52:16 +0800 Subject: [PATCH 2/3] Add block support to dismiss --- Classes/YIPopupTextView.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Classes/YIPopupTextView.h b/Classes/YIPopupTextView.h index 06b0cbf..6f0c4e4 100644 --- a/Classes/YIPopupTextView.h +++ b/Classes/YIPopupTextView.h @@ -25,12 +25,13 @@ typedef NS_ENUM(NSInteger, YIPopupTextViewButtonStyle) { @protocol YIPopupTextViewDelegate @optional -- (BOOL)popupTextView:(YIPopupTextView *)textView shouldDismissWithText:(NSString *)text cancelled:(BOOL)cancelled; - (void)popupTextView:(YIPopupTextView*)textView willDismissWithText:(NSString*)text cancelled:(BOOL)cancelled; - (void)popupTextView:(YIPopupTextView*)textView didDismissWithText:(NSString*)text cancelled:(BOOL)cancelled; @end +typedef void (^popupTextDidDismissBlock)(YIPopupTextView *textView, NSString * text, BOOL cancelled); +typedef void (^popupTextWillDismissBlock)(YIPopupTextView *textView, NSString * text, BOOL cancelled); @interface YIPopupTextView : YISSTextView @@ -43,6 +44,10 @@ typedef NS_ENUM(NSInteger, YIPopupTextViewButtonStyle) { @property (nonatomic) CGFloat topUIBarMargin; // set statusBar+navBar height for iOS7 fullscreen size manually @property (nonatomic) CGFloat bottomUIBarMargin; // set tabBar+toolbar height for iOS7 fullscreen size manually + +@property (nonatomic, copy) popupTextDidDismissBlock didDismiss; +@property (nonatomic, copy) popupTextWillDismissBlock willDismiss; + - (id)initWithPlaceHolder:(NSString*)placeHolder maxCount:(NSUInteger)maxCount; // YIPopupTextViewButtonStyleRightCancel @@ -66,5 +71,6 @@ typedef NS_ENUM(NSInteger, YIPopupTextViewButtonStyle) { - (void)dismiss; + @end From 753652c883abfe05ba571504ff276f07a8859bc7 Mon Sep 17 00:00:00 2001 From: taijizhu Date: Tue, 22 Mar 2016 11:57:29 +0000 Subject: [PATCH 3/3] expose buttons --- Classes/YIPopupTextView.h | 2 ++ Classes/YIPopupTextView.m | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/Classes/YIPopupTextView.h b/Classes/YIPopupTextView.h index d44eeed..1a306cd 100644 --- a/Classes/YIPopupTextView.h +++ b/Classes/YIPopupTextView.h @@ -71,6 +71,8 @@ typedef void (^popupTextWillDismissBlock)(YIPopupTextView *textView, NSString * - (void)dismiss; +- (UIButton*) getAcceptButton; +- (UIButton*) getCloseButton; @end diff --git a/Classes/YIPopupTextView.m b/Classes/YIPopupTextView.m index 33de311..9eb209d 100644 --- a/Classes/YIPopupTextView.m +++ b/Classes/YIPopupTextView.m @@ -343,6 +343,14 @@ - (NSUInteger)maxCount { return _maxCount; } +- (UIButton*) getAcceptButton { + return _acceptButton; +} + +- (UIButton*) getCloseButton { + return _closeButton; +} + - (void)setMaxCount:(NSUInteger)maxCount { _maxCount = maxCount; [self updateCount];