diff --git a/Classes/YIPopupTextView.h b/Classes/YIPopupTextView.h index 50dcb35..1a306cd 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,8 @@ typedef NS_ENUM(NSInteger, YIPopupTextViewButtonStyle) { - (void)dismiss; +- (UIButton*) getAcceptButton; +- (UIButton*) getCloseButton; + @end diff --git a/Classes/YIPopupTextView.m b/Classes/YIPopupTextView.m index e12c6e9..9eb209d 100644 --- a/Classes/YIPopupTextView.m +++ b/Classes/YIPopupTextView.m @@ -244,11 +244,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]; @@ -347,6 +343,14 @@ - (NSUInteger)maxCount { return _maxCount; } +- (UIButton*) getAcceptButton { + return _acceptButton; +} + +- (UIButton*) getCloseButton { + return _closeButton; +} + - (void)setMaxCount:(NSUInteger)maxCount { _maxCount = maxCount; [self updateCount]; @@ -406,7 +410,7 @@ - (void)showInView:(UIView*)view else { targetView = view; frame = view.bounds; - } + } _backgroundView.alpha = 0; _backgroundView.frame = frame; @@ -464,6 +468,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; @@ -475,6 +482,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; @@ -617,8 +627,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; } @@ -661,23 +675,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 @@ -799,4 +802,4 @@ - (void)shiftCaret self.selectedRange = range; } -@end \ No newline at end of file +@end