Skip to content

Commit b038f05

Browse files
committed
Merge commit '138fff60904d4de1bab9d9275ee98f90e0c964ee'
2 parents c2a542f + 138fff6 commit b038f05

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

QMUI/QMUIKit/UIComponents/QMUIModalPresentationViewController.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ + (void)initialize {
4848
@interface QMUIModalPresentationViewController ()
4949

5050
@property(nonatomic, strong) QMUIModalPresentationWindow *containerWindow;
51+
@property(nonatomic, weak) UIWindow *previousKeyWindow;
5152

5253
@property(nonatomic, assign) BOOL appearAnimated;
5354
@property(nonatomic, copy) void (^appearCompletionBlock)(BOOL finished);
@@ -197,8 +198,10 @@ - (void)viewWillDisappear:(BOOL)animated {
197198
void (^didHiddenCompletion)(BOOL finished) = ^(BOOL finished) {
198199

199200
if (self.containerWindow) {
201+
[self.previousKeyWindow makeKeyWindow];
200202
self.containerWindow.hidden = YES;
201203
self.containerWindow.rootViewController = nil;
204+
self.previousKeyWindow = nil;
202205
[self endAppearanceTransition];
203206
}
204207

@@ -384,17 +387,17 @@ - (void)showingAnimationWithCompletion:(void (^)(BOOL))completion {
384387
}
385388

386389
- (void)showWithAnimated:(BOOL)animated completion:(void (^)(BOOL))completion {
387-
// makeKeyAndVisible导致的viewWillAppear:必定animated是NO的,所以这里用额外的变量保存这个animated的值
390+
// makeKeyAndVisible 导致的 viewWillAppear: 必定 animated 是 NO 的,所以这里用额外的变量保存这个 animated 的值
388391
self.appearAnimated = animated;
389392
self.appearCompletionBlock = completion;
390-
393+
self.previousKeyWindow = [UIApplication sharedApplication].keyWindow;
391394
if (!self.containerWindow) {
392395
self.containerWindow = [[QMUIModalPresentationWindow alloc] init];
393396
self.containerWindow.windowLevel = UIWindowLevelQMUIAlertView;
394397
self.containerWindow.backgroundColor = UIColorClear;// 避免横竖屏旋转时出现黑色
395398
}
396399
self.containerWindow.rootViewController = self;
397-
self.containerWindow.hidden = NO;
400+
[self.containerWindow makeKeyAndVisible];
398401
}
399402

400403
- (void)hidingAnimationWithCompletion:(void (^)(BOOL))completion {

QMUI/QMUIKit/UIKitExtensions/UIView+QMUI.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ - (void)qmui_addSubview:(UIView *)view {
212212
}
213213

214214
- (BOOL)qmui_becomeFirstResponder {
215-
if (IS_SIMULATOR && ![self isKindOfClass:[UIWindow class]]) {
215+
if (IS_SIMULATOR && ![self isKindOfClass:[UIWindow class]] && self.window && !self.window.keyWindow) {
216216
[self QMUISymbolicUIViewBecomeFirstResponderWithoutKeyWindow];
217217
}
218218
return [self qmui_becomeFirstResponder];

0 commit comments

Comments
 (0)