Leave GLKView in place, obscured by snapshot

Generate the snapshot using `-[UIView snapshotViewAfterScreenUpdates:]` and place it _over_ the `GLKView`. UIKit appears to be able to detect that the `GLKView` is completely obscured and avoids `-_display`ing it.
This commit is contained in:
Minh Nguyễn
2015-04-14 22:23:13 -07:00
parent c5b0478e9a
commit e19b6afb26

View File

@@ -67,8 +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;
/** A static view to simulate and obscure `glView` when the app is in the background. */
@property (nonatomic) UIView *glSnapshotView;
@property (nonatomic) NSOperationQueue *regionChangeDelegateQueue;
@property (nonatomic) UIImageView *compass;
@property (nonatomic) UIImageView *logoBug;
@@ -243,12 +243,6 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
_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
@@ -568,8 +562,11 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
// This is the delegate of the GLKView object's display call.
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight);
mbglMap->renderSync();
if (!self.glSnapshotView)
{
mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight);
mbglMap->renderSync();
}
}
// This gets called when the view dimension changes, e.g. because the device is being rotated.
@@ -592,9 +589,9 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
{
[MGLMapboxEvents flush];
UIImage *snapshot = [self.glView snapshot];
self.glImpersonatingView.image = snapshot;
[self.glView removeFromSuperview];
self.glSnapshotView = [self.glView snapshotViewAfterScreenUpdates:YES];
self.glSnapshotView.autoresizingMask = self.glView.autoresizingMask;
[self insertSubview:self.glSnapshotView aboveSubview:self.glView];
mbglMap->stop();
@@ -607,7 +604,8 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
mbglMap->start();
[self insertSubview:self.glView aboveSubview:self.glImpersonatingView];
[self.glSnapshotView removeFromSuperview];
self.glSnapshotView = nil;
}
- (void)tintColorDidChange