From 3157f8a1505685bd5aab2414aff6f7a31b9561ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=88=AA?= Date: Fri, 24 Nov 2017 20:39:34 +0800 Subject: [PATCH] Add property --- TapkuLibrary/TKAlertCenter.h | 4 +++- TapkuLibrary/TKAlertCenter.m | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) 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