From 79036b9550fa012d57e44cff261d5855a8420770 Mon Sep 17 00:00:00 2001 From: Benoit Pasquier Date: Sun, 6 Dec 2015 18:14:07 +0000 Subject: [PATCH 1/3] Define completion block property to be automatically executed. --- STPopup/STPopupController.h | 2 ++ STPopup/STPopupController.m | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/STPopup/STPopupController.h b/STPopup/STPopupController.h index 2563ae7..d805e27 100644 --- a/STPopup/STPopupController.h +++ b/STPopup/STPopupController.h @@ -29,6 +29,8 @@ typedef NS_ENUM(NSUInteger, STPopupTransitionStyle) { @property (nonatomic, strong) UIView *backgroundView; @property (nonatomic, assign, readonly) BOOL presented; +@property (nonatomic, strong) (void (^)(void))completion; + - (instancetype)initWithRootViewController:(UIViewController *)rootViewController; - (void)presentInViewController:(UIViewController *)viewController; diff --git a/STPopup/STPopupController.m b/STPopup/STPopupController.m index ddac0df..100b472 100644 --- a/STPopup/STPopupController.m +++ b/STPopup/STPopupController.m @@ -227,7 +227,11 @@ - (void)presentInViewController:(UIViewController *)viewController completion:(v - (void)dismiss { - [self dismissWithCompletion:nil]; + if (self.completion) { + [self dismissWithCompletion:self.completion]; + } else { + [self dismissWithCompletion:nil]; + } } - (void)dismissWithCompletion:(void (^)(void))completion From d33aa41be1ec44550d62371784caa951ecf20b16 Mon Sep 17 00:00:00 2001 From: Benoit PASQUIER Date: Tue, 5 Jan 2016 13:49:26 +0000 Subject: [PATCH 2/3] Update closeCompletion block --- STPopup/STPopupController.h | 2 +- STPopup/STPopupController.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/STPopup/STPopupController.h b/STPopup/STPopupController.h index 8ed0aa5..7b8afe0 100644 --- a/STPopup/STPopupController.h +++ b/STPopup/STPopupController.h @@ -29,7 +29,7 @@ typedef NS_ENUM(NSUInteger, STPopupTransitionStyle) { @property (nonatomic, strong) UIView *backgroundView; @property (nonatomic, assign, readonly) BOOL presented; -@property (nonatomic, strong) (void (^)(void))completion; +@property (nonatomic, strong) void (^closeCompletion)(void); - (instancetype)initWithRootViewController:(UIViewController *)rootViewController; diff --git a/STPopup/STPopupController.m b/STPopup/STPopupController.m index b2a29c4..c9353e8 100644 --- a/STPopup/STPopupController.m +++ b/STPopup/STPopupController.m @@ -227,8 +227,8 @@ - (void)presentInViewController:(UIViewController *)viewController completion:(v - (void)dismiss { - if (self.completion) { - [self dismissWithCompletion:self.completion]; + if (_closeCompletion) { + [self dismissWithCompletion:_closeCompletion]; } else { [self dismissWithCompletion:nil]; } From 9fc75108a257cf6c478f3f401681c58d1dc26938 Mon Sep 17 00:00:00 2001 From: Benoit PASQUIER Date: Tue, 24 May 2016 17:52:11 +0100 Subject: [PATCH 3/3] Add "ignoreKeyboardEvent" property to avoid moving the window for web content. --- STPopup/STPopupController.h | 1 + STPopup/STPopupController.m | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/STPopup/STPopupController.h b/STPopup/STPopupController.h index 7b8afe0..bda8234 100644 --- a/STPopup/STPopupController.h +++ b/STPopup/STPopupController.h @@ -30,6 +30,7 @@ typedef NS_ENUM(NSUInteger, STPopupTransitionStyle) { @property (nonatomic, assign, readonly) BOOL presented; @property (nonatomic, strong) void (^closeCompletion)(void); +@property (nonatomic, assign) BOOL ignoreKeyboardEvent; - (instancetype)initWithRootViewController:(UIViewController *)rootViewController; diff --git a/STPopup/STPopupController.m b/STPopup/STPopupController.m index c9353e8..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];