diff --git a/STPopup/STPopupController.h b/STPopup/STPopupController.h index e52c656..bda8234 100644 --- a/STPopup/STPopupController.h +++ b/STPopup/STPopupController.h @@ -29,6 +29,9 @@ typedef NS_ENUM(NSUInteger, STPopupTransitionStyle) { @property (nonatomic, strong) UIView *backgroundView; @property (nonatomic, assign, readonly) BOOL presented; +@property (nonatomic, strong) void (^closeCompletion)(void); +@property (nonatomic, assign) BOOL ignoreKeyboardEvent; + - (instancetype)initWithRootViewController:(UIViewController *)rootViewController; - (void)presentInViewController:(UIViewController *)viewController; diff --git a/STPopup/STPopupController.m b/STPopup/STPopupController.m index 173f46d..3fc5475 100644 --- a/STPopup/STPopupController.m +++ b/STPopup/STPopupController.m @@ -145,10 +145,14 @@ - (void)setupObservers // Observe orientation change [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; - // Observe keyboard - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; + if (!_ignoreKeyboardEvent) { + + // Observe keyboard + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; + } + // Observe responder change [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(firstResponderDidChange) name:STPopupFirstResponderDidChangeNotification object:nil]; @@ -227,7 +231,11 @@ - (void)presentInViewController:(UIViewController *)viewController completion:(v - (void)dismiss { - [self dismissWithCompletion:nil]; + if (_closeCompletion) { + [self dismissWithCompletion:_closeCompletion]; + } else { + [self dismissWithCompletion:nil]; + } } - (void)dismissWithCompletion:(void (^)(void))completion