Skip to content
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
10 changes: 9 additions & 1 deletion Classes/YIPopupTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ typedef NS_ENUM(NSInteger, YIPopupTextViewButtonStyle) {

@protocol YIPopupTextViewDelegate <UITextViewDelegate>
@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

Expand All @@ -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

Expand All @@ -66,5 +71,8 @@ typedef NS_ENUM(NSInteger, YIPopupTextViewButtonStyle) {

- (void)dismiss;

- (UIButton*) getAcceptButton;
- (UIButton*) getCloseButton;

@end

47 changes: 25 additions & 22 deletions Classes/YIPopupTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -347,6 +343,14 @@ - (NSUInteger)maxCount {
return _maxCount;
}

- (UIButton*) getAcceptButton {
return _acceptButton;
}

- (UIButton*) getCloseButton {
return _closeButton;
}

- (void)setMaxCount:(NSUInteger)maxCount {
_maxCount = maxCount;
[self updateCount];
Expand Down Expand Up @@ -406,7 +410,7 @@ - (void)showInView:(UIView*)view
else {
targetView = view;
frame = view.bounds;
}
}

_backgroundView.alpha = 0;
_backgroundView.frame = frame;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -799,4 +802,4 @@ - (void)shiftCaret
self.selectedRange = range;
}

@end
@end