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

Closed

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.

Activity

  1. added
    iOS
    on Oct 4, 2016
  2. 1ec5 commented on Oct 7, 2016

    @1ec5
    Contributor

    This may be related to the ambiguous constraint warnings we’re seeing for the ℹ️ button, compass view, etc.: #5549.

  3. ketz commented on Nov 16, 2016

    @ketz

    @u10int - did you ever find a way to improve that animation?
    Having the exact same problem, and it makes it look really bad when animating.

  4. 1ec5 commented on Nov 16, 2016

    @1ec5
    Contributor

    #6776 fixes some issues with the map view's internal constraints, but some known problems remain: #6954.

    One workaround for your issue may be to hide the compass, logo view, and attribution button during the animation and show them again afterwards.

  5. ketz commented on Nov 16, 2016

    @ketz

    @1ec5 - sadly, hiding those (even permanently to test properly), didn't work.
    Here's a quick video to show it happening (with a red background on the map view to highlight the issue):
    https://dl.dropboxusercontent.com/u/1977230/MapboxBug.mp4

  6. friedbunny commented on Dec 12, 2016

    @friedbunny
    Contributor

    @frederoni Any sense if #7084 (or other related changes) address this issue?

  7. frederoni commented on Dec 12, 2016

    @frederoni
    Contributor

    #7084 most likely resolved this issue but there's a lot going on #6568 (comment) here with custom transitions so another test using the latest beta version of the SDK would be great. Though it's not only the attribution that's misaligned/missing but the speed of the animation when resizing the map view's frame is not in sync with the constraints if I'm not mistaken? (#6568 (comment))

  8. ketz commented on Dec 13, 2016

    @ketz

    Yes, the issue is the discrepancy between frame animations, which makes the map reveal the background.
    I'll give it a go with the Beta SDK as soon as I get a chance

  9. lilykaiser commented on Nov 17, 2017

    @lilykaiser

    Closing due to ticket age. If this is still a problem, please re-open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugiOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions