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

Wrong attribution positioning after resizing MGLMapView via constraints #6568

Closed
u10int opened this issue Oct 4, 2016 · 8 comments
Closed
Labels
bug iOS Mapbox Maps SDK for iOS

Comments

@u10int
Copy link

u10int commented Oct 4, 2016

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.

@boundsj boundsj added bug iOS Mapbox Maps SDK for iOS labels Oct 4, 2016
@1ec5
Copy link
Contributor

1ec5 commented Oct 7, 2016

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

@ketz
Copy link

ketz commented Nov 16, 2016

@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.

@1ec5
Copy link
Contributor

1ec5 commented Nov 16, 2016

#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.

@ketz
Copy link

ketz commented Nov 16, 2016

@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

@friedbunny
Copy link
Contributor

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

@frederoni
Copy link
Contributor

frederoni commented Dec 12, 2016

#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))

@ketz
Copy link

ketz commented Dec 13, 2016

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

@lilykaiser
Copy link

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

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

7 participants