Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Prevent black flash when loading styles #3101

Closed
tomtaylor opened this issue Nov 23, 2015 · 9 comments
Closed

Prevent black flash when loading styles #3101

tomtaylor opened this issue Nov 23, 2015 · 9 comments
Labels
bug iOS Mapbox Maps SDK for iOS
Milestone

Comments

@tomtaylor
Copy link

I've set a background colour on my MGLMapView, to the background of the Streets style, so it looks a little less jarring when loading. However, it still flashes black while loading the map for the first time. It'd be great if it could keep the background colour until the style is fully loaded.

@1ec5
Copy link
Contributor

1ec5 commented Nov 23, 2015

This would be fixed by #3096 I believe.

@1ec5 1ec5 added bug iOS Mapbox Maps SDK for iOS labels Nov 23, 2015
@tomtaylor
Copy link
Author

Ah ha, thanks.

@abpopov
Copy link

abpopov commented Dec 9, 2015

I solve this by this code
mapView.layer.backgroundColor =[[UIColor clearColor] CGColor];

@friedbunny friedbunny added this to the ios-v3.1.0 milestone Jan 15, 2016
@friedbunny
Copy link
Contributor

Fixed by #3096.

@1ec5
Copy link
Contributor

1ec5 commented Jan 15, 2016

The fix in #3096 only takes effect if you set MGLMapView.opaque = NO; otherwise, UIKit considers the behavior to be undefined if the map view fails to draw its entire bounds. So setting opaque = NO is the recommended way to deal with the black flash.

chainedtothewoods added a commit to chainedtothewoods/WeatherMap that referenced this issue Jul 20, 2016
@mxcl
Copy link

mxcl commented Nov 30, 2016

isOpaque should be false by default since that is the behavior of almost all UIKit views since iOS 7 almost four years ago. The black flash alone is why my boss decided that we would use Google Maps instead. :P

@1ec5
Copy link
Contributor

1ec5 commented Nov 30, 2016

As of the iOS 10 SDK, UIView.isOpaque is true by default, and so is MKMapView.isOpaque.

The black flash you’re seeing is more likely the style’s background layer being rendered before the other layers come in, since the other layers likely require fetching vector tiles. (This is the phase in which MapKit would render a graticule: see #119.)

The background color of a style usually matches the color of land, although Mapbox Satellite and Satellite Streets have black as their background color. You can configure the background color by customizing a style in Mapbox Studio or, as of the upcoming Mapbox iOS SDK v3.4.0 beta, by modifying (mapView.style.layers.last as? MGLBackgroundStyleLayer)?.backgroundColor inside MGLMapViewDelegate.mapView(_:didFinishLoadingStyle:).

If you’re seeing a noticeable black flash despite the style’s background color being set to something lighter, I agree that we should revisit this issue and find a better solution.

@mxcl
Copy link

mxcl commented Dec 1, 2016

UIView, probably, the majority of UIKit, certainly not. It is easy enough to test, almost all of my apps are clear background views (UILabel, UITableView, UIButton, UI*) and I get no black flashes due to opaqueness being true.

The black flash you’re seeing is more likely the style’s background layer being rendered before the other layers come in, since the other layers likely require fetching vector tiles. (This is the phase in which MapKit would render a graticule: see #119.)

I set isOpaque to false and the black flash stopped…

@1ec5
Copy link
Contributor

1ec5 commented Dec 1, 2016

I don’t mean to be stubborn; just wondering whether we’re missing something that allows MapKit to default to being opaque but still avoid the black flash. I’ve opened #7256 to track defaulting isOpaque to NO, as you’ve requested.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

5 participants