Mapbox-gl-native: MGLMapView contentInset top is ignored for compass positioning

Created on 26 Jan 2018  ·  6Comments  ·  Source: mapbox/mapbox-gl-native

Platform: iOS
Mapbox SDK version: 3.7.3

Hi there,

We have been using contentInset.top to position the compass on our MGLMapView, in order to move it out of the way of some other views that we place on top of the map view. This has worked fine until recently, but was broken in Mapbox 3.7.2.

Steps to trigger behavior

Our usage looks like this: (Swift; edited for clarity)

let mapView = MGLMapView(frame: UIScreen.main.bounds, styleURL: styleURL)
mapView.zoomLevel = 12
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: false)
mapView.contentInset = UIEdgeInsets(top: 60, left: 0, bottom: 0, right: 0)
mapView.updateConstraints()
mapView.delegate = self
view.insertSubview(mapView, at: 0)

Expected behavior

The compass should be positioned at least 60 points below the top of the MGLMapView.

Actual behavior

The compass is positioned at the top of MGLMapView. Setting contentInset makes no difference to the vertical positioning.

More info

I regression tested it on these Mapbox versions:

3.6.4: ✅ as expected
3.7.0: ✅ as expected
3.7.1: ✅ as expected
3.7.2: ❌ not as expected
3.7.3: ❌ not as expected

I think this commit may have been the breaking change: https://github.com/mapbox/mapbox-gl-native/commit/d650b91c00956b683519aa76b3f5dfd327c17348

Note that the left side of the diff references contentInset.top but the right side does not.

Question


Is this a bug, or was this change intentional? If the latter, do you have another recommendation for how to position the compass?

Thanks!

bug iOS

All 6 comments

Is there any workaround?

@dmdeller can you confirm that automaticallyAdjustsScrollViewInsets was set to NO?

@julianrex Confirmed, automaticallyAdjustsScrollViewInsets was set to NO. The problem occurs whether this is set to NO or YES. I also confirmed it still occurs under Mapbox 4.5.0.

Making a note that the ideal solution here should involve integrating the Adopt layout anchors #12147 PR.

Noting that this issue should be addressed by https://github.com/mapbox/mapbox-gl-native/pull/13911 which is currently in review. /cc @chloekraw

@dmdeller https://github.com/mapbox/mapbox-gl-native/pull/13911 has now merged and will be available in an upcoming release. This is the supported mechanism for moving "ornaments" like the compass.

I'm going to close this issue, but please reopen if necessary!

Was this page helpful?
0 / 5 - 0 ratings