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

Wrong attribution positioning after resizing MGLMapView via constraints #6568

@u10int

Description

@u10int

There seems to be an issue when resizing an MGLMapView via AutoLayout constraints during a custom view controller transition animation that breaks the layout of the attribution views that are normally at the bottom corners. My view controller transition consists of expanding the map view full screen from a smaller frame in the presenting profile/detail controller.

During the transition, the MGLMapView instance from the detail/profile controller is added as a subview of the destination/target view controller after which the necessary AutoLayout constraints are setup and then animated from the starting frame to the destination (full screen) frame. It appears that perhaps changing the map view's parent in this process may be breaking the position of the logo and attribution views at the bottom of the map.

When working with Mapbox support a few months ago on the issue, it was believed the cause was related to this issue. But the latest SDK versions still have the issue.

Here's a screen capture of the issue:

mapbox-logo-position

Platform: iOS 8.0+
Mapbox SDK: 3.3.4

Here's condensed version of the code that performs this presentation transition animation via the UIViewControllerAnimatedTransitioning protocol:

let toViewController = toViewControllerInContext(transitionContext)
let targetViewController = targetViewControllerForKey(UITransitionContextToViewControllerKey, inContext: transitionContext)

transitionContext.containerView().addSubview(toViewController!.view)

if let mapController = targetViewController as? MapViewController, mapView = mapController.mapView {
    mapController.view.layoutIfNeeded()

    let originalMapSuperview = mapView.superview
    let targetMapFrame = mapController.mapContainerView.convertRect(originalMapSuperview!.frame, fromView: originalMapSuperview!.superview!)
    mapController.mapContainerView.addSubview(mapView)

    var mapHeightConstraint: NSLayoutConstraint?
    var mapTopConstraint: NSLayoutConstraint?

    constrain(mapView) { view in
        view.left == view.superview!.left
        view.right == view.superview!.right
        mapHeightConstraint = (view.height == CGRectGetHeight(targetMapFrame))
        mapTopConstraint = (view.top == view.superview!.top + CGRectGetMinY(targetMapFrame))
    }

    mapHeightConstraint?.constant = CGRectGetHeight(mapController.mapContainerView.frame)
    mapTopConstraint?.constant = 0
    UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
        mapController.view.layoutIfNeeded()
        }, completion: { (finished) -> Void in
            transitionContext.completeTransition(true)
    })
}

Expected behavior

The map view's attribution views should remain pinned to the bottom corners of the map when animating its layout constraints.

Actual behavior

The map view's attribution views break their layout when animating the map view's layout constraints.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugiOSMapbox Maps SDK for iOS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions