diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 22a3457aa..dfd38abf6 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -67,8 +67,7 @@ static NSURL *MGLURLForBundledStyleNamed(NSString *styleName) @property (nonatomic) EAGLContext *context; @property (nonatomic) GLKView *glView; -/** A static view to simulate and obscure `glView` when the app is in the background. */ -@property (nonatomic) UIView *glSnapshotView; +@property (nonatomic) UIImageView *glSnapshotView; @property (nonatomic) NSOperationQueue *regionChangeDelegateQueue; @property (nonatomic) UIImageView *compass; @property (nonatomic) UIImageView *logoBug; @@ -563,16 +562,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; // This is the delegate of the GLKView object's display call. - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { - if (self.glSnapshotView) - { - NSUInteger snapshotIdx = [self.subviews indexOfObject:self.glSnapshotView]; - NSUInteger glIdx = [self.subviews indexOfObject:self.glView]; - NSAssert(snapshotIdx > glIdx, - @"The snapshot view is the %luth subview, behind the GL view, which is the %luth. " - @"The snapshot view should obscure the GL view to prevent crashing while the app is in the background.", - (unsigned long)snapshotIdx, (unsigned long)glIdx); - } - else + if ( ! self.glSnapshotView || self.glSnapshotView.isHidden) { mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight); @@ -609,11 +599,17 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; - (void)appDidBackground:(NSNotification *)notification { [MGLMapboxEvents flush]; - - self.glSnapshotView = [self.glView snapshotViewAfterScreenUpdates:YES]; - self.glSnapshotView.autoresizingMask = self.glView.autoresizingMask; - [self insertSubview:self.glSnapshotView aboveSubview:self.glView]; - + + if ( ! self.glSnapshotView) + { + self.glSnapshotView = [[UIImageView alloc] initWithFrame:self.glView.frame]; + self.glSnapshotView.autoresizingMask = self.glView.autoresizingMask; + [self insertSubview:self.glSnapshotView aboveSubview:self.glView]; + } + + self.glSnapshotView.image = self.glView.snapshot; + self.glSnapshotView.hidden = NO; + mbglMap->stop(); [self.glView deleteDrawable]; @@ -621,12 +617,11 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; - (void)appWillForeground:(NSNotification *)notification { + self.glSnapshotView.hidden = YES; + [self.glView bindDrawable]; mbglMap->start(); - - [self.glSnapshotView removeFromSuperview]; - self.glSnapshotView = nil; } - (void)tintColorDidChange