From 45ddac5c5d5ef79618aeefc6d74120e66091ba5e Mon Sep 17 00:00:00 2001 From: Andrey Volodin Date: Tue, 6 Oct 2015 18:38:47 +0300 Subject: [PATCH] More predictable behaviour when using destination view --- KLCPopup/KLCPopup.h | 2 ++ KLCPopup/KLCPopup.m | 30 ++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/KLCPopup/KLCPopup.h b/KLCPopup/KLCPopup.h index 36fe364..c6c8c43 100644 --- a/KLCPopup/KLCPopup.h +++ b/KLCPopup/KLCPopup.h @@ -21,6 +21,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#import +#import // KLCPopupShowType: Controls how the popup will be presented. typedef NS_ENUM(NSInteger, KLCPopupShowType) { diff --git a/KLCPopup/KLCPopup.m b/KLCPopup/KLCPopup.m index f297cce..722e55c 100644 --- a/KLCPopup/KLCPopup.m +++ b/KLCPopup/KLCPopup.m @@ -529,18 +529,21 @@ - (void)showWithParameters:(NSDictionary*)parameters { [self willStartShowing]; dispatch_async( dispatch_get_main_queue(), ^{ - - // Prepare by adding to the top window. - if(!self.superview){ - NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication] windows] reverseObjectEnumerator]; - - for (UIWindow *window in frontToBackWindows) { - if (window.windowLevel == UIWindowLevelNormal) { - [window addSubview:self]; - - break; - } + UIView* destView; + if(!self.superview) { + destView = [parameters valueForKey:@"view"]; + if (destView == nil) { + // Prepare by adding to the top window. + NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication] windows] reverseObjectEnumerator]; + + for (UIWindow *window in frontToBackWindows) + if (window.windowLevel == UIWindowLevelNormal) { + destView = window; + break; + } } + [destView addSubview:self]; + [destView bringSubviewToFront:self]; } // Before we calculate layout for containerView, make sure we are transformed for current orientation. @@ -647,9 +650,8 @@ - (void)showWithParameters:(NSDictionary*)parameters { CGPoint centerInSelf; // Convert coordinates from provided view to self. Otherwise use as-is. - UIView* fromView = [parameters valueForKey:@"view"]; - if (fromView != nil) { - centerInSelf = [self convertPoint:centerInView fromView:fromView]; + if (destView != nil) { + centerInSelf = [self convertPoint:centerInView fromView:destView]; } else { centerInSelf = centerInView; }