Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More predictable behaviour when using destination view #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions KLCPopup/KLCPopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

// KLCPopupShowType: Controls how the popup will be presented.
typedef NS_ENUM(NSInteger, KLCPopupShowType) {
Expand Down
30 changes: 16 additions & 14 deletions KLCPopup/KLCPopup.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down