From c5b0478e9abf9dc1f1f659e7d5a0e2f89602ef29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Fri, 10 Apr 2015 14:29:18 -0700 Subject: [PATCH] Detach GLKView while app is in background MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Throw a static snapshot up for the app switcher. Hope you didn’t plan on moving markers around while the app is in the background. Fixes #1050, #1186, #1203, #1243. --- platform/ios/MGLMapView.mm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index f70f9f348..afea8ae4f 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -67,6 +67,8 @@ static NSURL *MGLURLForBundledStyleNamed(NSString *styleName) @property (nonatomic) EAGLContext *context; @property (nonatomic) GLKView *glView; +/** A static view to impersonate `glView` when the app is in the background. */ +@property (nonatomic) UIImageView *glImpersonatingView; @property (nonatomic) NSOperationQueue *regionChangeDelegateQueue; @property (nonatomic) UIImageView *compass; @property (nonatomic) UIImageView *logoBug; @@ -240,6 +242,13 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; [self insertSubview:_glView atIndex:0]; _glView.contentMode = UIViewContentModeCenter; + + // create GL impersonating view + // + _glImpersonatingView = [[UIImageView alloc] initWithFrame:_glView.frame]; + _glImpersonatingView.autoresizingMask = _glView.autoresizingMask; + [self insertSubview:_glImpersonatingView belowSubview:_glView]; + [self setBackgroundColor:[UIColor clearColor]]; // load extensions @@ -583,6 +592,10 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; { [MGLMapboxEvents flush]; + UIImage *snapshot = [self.glView snapshot]; + self.glImpersonatingView.image = snapshot; + [self.glView removeFromSuperview]; + mbglMap->stop(); [self.glView deleteDrawable]; @@ -593,6 +606,8 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; [self.glView bindDrawable]; mbglMap->start(); + + [self insertSubview:self.glView aboveSubview:self.glImpersonatingView]; } - (void)tintColorDidChange