diff --git a/TapkuLibrary/TKAlertCenter.h b/TapkuLibrary/TKAlertCenter.h index 5fa00c8f..e28efb4e 100644 --- a/TapkuLibrary/TKAlertCenter.h +++ b/TapkuLibrary/TKAlertCenter.h @@ -42,6 +42,8 @@ CGRect _alertFrame; } +@property (weak, nonatomic) UIWindow *keyWindow; + /** Returns the process’s default notification center. @return The current process’s default notification center, which is used for alert notifications. */ @@ -59,4 +61,4 @@ */ - (void) postAlertWithMessage:(NSString *)message; -@end \ No newline at end of file +@end diff --git a/TapkuLibrary/TKAlertCenter.m b/TapkuLibrary/TKAlertCenter.m index 04ab1130..52427346 100644 --- a/TapkuLibrary/TKAlertCenter.m +++ b/TapkuLibrary/TKAlertCenter.m @@ -148,7 +148,7 @@ - (instancetype) init{ _active = NO; - _alertFrame = [UIScreen mainScreen].applicationFrame; + _alertFrame = [UIScreen mainScreen].bounds; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil]; @@ -172,9 +172,13 @@ - (void) showAlerts{ _active = YES; _alertView.transform = CGAffineTransformIdentity; _alertView.alpha = 0; - [[UIApplication sharedApplication].keyWindow addSubview:_alertView]; - - + + if (_keyWindow) + [_keyWindow addSubview:_alertView]; + else + [[UIApplication sharedApplication].keyWindow addSubview:_alertView]; + + NSArray *ar = _alerts[0]; @@ -298,7 +302,7 @@ - (void) keyboardWillAppear:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; NSValue* aValue = userInfo[UIKeyboardFrameEndUserInfoKey]; CGRect kf = [aValue CGRectValue]; - CGRect wf = [UIScreen mainScreen].applicationFrame; + CGRect wf = [UIScreen mainScreen].bounds; [UIView beginAnimations:nil context:nil]; _alertFrame = subtractRect(wf,kf); @@ -307,7 +311,7 @@ - (void) keyboardWillAppear:(NSNotification *)notification { } - (void) keyboardWillDisappear:(NSNotification *) notification { - _alertFrame = [UIScreen mainScreen].applicationFrame; + _alertFrame = [UIScreen mainScreen].bounds; } - (void) orientationWillChange:(NSNotification *) notification { @@ -331,4 +335,4 @@ - (void) orientationWillChange:(NSNotification *) notification { } -@end \ No newline at end of file +@end