From 9de1dcd373fa9b2f26c58bdcd5bcd35a44eb27ac Mon Sep 17 00:00:00 2001 From: Alexei Gridnev Date: Sat, 19 Nov 2016 21:21:04 +0200 Subject: [PATCH] Use sharedApplication window when _inView.window is nil --- WYPopoverController/WYPopoverController.m | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/WYPopoverController/WYPopoverController.m b/WYPopoverController/WYPopoverController.m index 0fb4c40c..8171b53a 100644 --- a/WYPopoverController/WYPopoverController.m +++ b/WYPopoverController/WYPopoverController.m @@ -1762,6 +1762,10 @@ - (void)presentPopoverFromRect:(CGRect)aRect completion:nil]; } +- (UIWindow *)getWindow { + return _inView.window == nil ? [[[UIApplication sharedApplication] delegate] window] : _inView.window; +} + - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArrowDirections:(WYPopoverArrowDirection)aArrowDirections @@ -1786,7 +1790,7 @@ - (void)presentPopoverFromRect:(CGRect)aRect CGSize contentViewSize = self.popoverContentSize; if (_overlayView == nil) { - _overlayView = [[WYPopoverOverlayView alloc] initWithFrame:_inView.window.bounds]; + _overlayView = [[WYPopoverOverlayView alloc] initWithFrame:[self getWindow].bounds]; _overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _overlayView.autoresizesSubviews = NO; _overlayView.delegate = self; @@ -1808,8 +1812,8 @@ - (void)presentPopoverFromRect:(CGRect)aRect [_backgroundView addGestureRecognizer:tap]; } - [_inView.window addSubview:_backgroundView]; - [_inView.window insertSubview:_overlayView belowSubview:_backgroundView]; + [[self getWindow] addSubview:_backgroundView]; + [[self getWindow] insertSubview:_overlayView belowSubview:_backgroundView]; } [self updateThemeUI]; @@ -1842,8 +1846,8 @@ - (void)presentPopoverFromRect:(CGRect)aRect void (^adjustTintDimmed)() = ^() { #ifdef WY_BASE_SDK_7_ENABLED - if (_backgroundView.dimsBackgroundViewsTintColor && [_inView.window respondsToSelector:@selector(setTintAdjustmentMode:)]) { - for (UIView *subview in _inView.window.subviews) { + if (_backgroundView.dimsBackgroundViewsTintColor && [[self getWindow] respondsToSelector:@selector(setTintAdjustmentMode:)]) { + for (UIView *subview in [self getWindow].subviews) { if (subview != _backgroundView) { [subview setTintAdjustmentMode:UIViewTintAdjustmentModeDimmed]; } @@ -2087,7 +2091,7 @@ - (void)positionPopover:(BOOL)aAnimated { WYPopoverArrowDirection arrowDirection = _permittedArrowDirections; - _overlayView.bounds = _inView.window.bounds; + _overlayView.bounds = [self getWindow].bounds; _backgroundView.transform = CGAffineTransformIdentity; viewFrame = [_inView convertRect:_rect toView:nil]; @@ -2402,8 +2406,8 @@ - (void)dismissPopoverAnimated:(BOOL)aAnimated void (^adjustTintAutomatic)() = ^() { #ifdef WY_BASE_SDK_7_ENABLED - if ([_inView.window respondsToSelector:@selector(setTintAdjustmentMode:)]) { - for (UIView *subview in _inView.window.subviews) { + if ([[self getWindow] respondsToSelector:@selector(setTintAdjustmentMode:)]) { + for (UIView *subview in [self getWindow].subviews) { if (subview != _backgroundView) { [subview setTintAdjustmentMode:UIViewTintAdjustmentModeAutomatic]; }