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.

Animating map view contraints is jerky; implicit animation via Core Animation properties not supported #4352

Open

Description

@friedbunny

The proper way to animate MGLMapView is to modify its auto layout constraints (and not the frame), but this doesn’t behave correctly:

  • White gaps at top and bottom jump as the map frame instantly shrinks to fit, rather than animate to the new, smaller constraint. The logo and attribution subviews do animate correctly, which indicates this is an issue with the GLKView that provides the map itself.
  • User location annotation does not move, it just sits around waiting to be in the correct spot again.

animating-constraint-jumping

Preview of the test project:

screen shot 2016-03-16 at 3 10 26 pm

import UIKit
import Mapbox

class ViewController: UIViewController {

    @IBOutlet weak var mapView: MGLMapView!
    @IBOutlet weak var heightConstraint: NSLayoutConstraint!

    override func viewDidLoad() {
        super.viewDidLoad()
        mapView.showsUserLocation = true
    }

    @IBAction func animate(sender: AnyObject) {
        UIView.animateWithDuration(1.5, delay: 0, options: .CurveEaseOut, animations: {
            self.mapView.userInteractionEnabled = false

            self.heightConstraint.constant = self.heightConstraint.constant > 200 ? 200 : self.view.frame.height/2

            self.view.layoutIfNeeded()
        }, completion: { finished in
            self.mapView.userInteractionEnabled = true
        })
    }

}

/cc @1ec5 @boundsj

Activity

  1. added
    iOS
    on Mar 16, 2016
  2. harri121 commented on Mar 31, 2016

    @harri121

    +1

  3. harri121 commented on Apr 17, 2016

    @harri121

    Is there a workaround?

  4. 1ec5 commented on Apr 17, 2016

    @1ec5
    Contributor

    I’m not sure about a workaround, but I suspect the problem may be that -layoutSubviews only gets called at the beginning of the animation, so mbgl::Map::update() gets called only once with the final size. Meanwhile, the user dot appears to stay stationary because it’s actually animating in the opposite direction to compensate. (If the map view is flush with the bottom of the view controller, showing and hiding the bottom bar will cause the user dot to visibly slide into place.)

  5. 1ec5 commented on Apr 17, 2016

    @1ec5
    Contributor

    The fix is probably to move the call to mbgl::Map::update() from -layoutSubviews to the -setFrame: or -setBounds: override and also have MBGLView::getSize() return GLKView’s presentation layer’s size instead of MGLMapView’s explicit size.

  6. added this to the ios-v3.3.0 milestone on Apr 17, 2016
  7. harri121 commented on Apr 17, 2016

    @harri121

    Ok, do you know when this will be fixed?

  8. modified the milestones: ios-v3.4.0, ios-future on Jul 11, 2016
  9. afinlayson commented on Aug 7, 2016

    @afinlayson

    Looking for this as well.
    Thanks

  10. 9 remaining items

  11. katiesmillie commented on Mar 23, 2019

    @katiesmillie

    This is still an issue that I've been following and hoping for a resolution. I hope you'll consider re-opening it.

    The best workaround that I've come up with is to leave the size of the mapview unchanged, and change the content insets of the map (which adjusts the coordinates bounds and center of the map). The map animation happens after the second view has been finished animating so you lose the effect you see above where they both animate together. This significantly degrades the experience as it has become a very common mobile UI pattern with all the major map apps.

  12. removed
    archived
    on Mar 25, 2019
  13. julianrex commented on Mar 25, 2019

    @julianrex
    Contributor

    This is still open @katiesmillie!

    Your workaround of changing the content insets may actually be part of the solution that we're looking at (or similar) - since adjusting the frame buffers during an animation gives poor performance.

  14. removed their assignment
    on Apr 8, 2019
  15. pappalar commented on Apr 11, 2019

    @pappalar

    +1 for this issue

  16. pappalar commented on Apr 29, 2019

    @pappalar

    The same issue is also happening when the iOS tab bar or Navigation Bar are showing animated. as the container of the map will change constrains animated.

    I also noticed that changing the content inset (animated if I remember correctly) also does not redraw the current location annotation position (as originally reported)

  17. 1ec5 commented on May 13, 2019

    @1ec5
    Contributor

    The root cause of the original report is that MGLMapView.camera, centerCoordinate, etc. are not implicitly animatable. (Notice how the constraint is being modified inside an implicit animation block.) Supporting implicit animation for the camera properties would be one side effect of reimplementing camera animation atop Core Animation: #9808.

  18. 1ec5 commented on May 29, 2019

    @1ec5
    Contributor

    Replacing GLKView with a built-in Core Animation layer (#14785) would make the effect somewhat less jarring, as it is on macOS. The layer’s frame would animate correctly, though the content could potentially stretch or compress to fit that frame during the animation. Supporting implicit animation is the correct fix no matter what.

  19. pappalar commented on Jun 27, 2019

    @pappalar

    @1ec5 Would it be possible and is the idea to support animation for the camera and centerCoordinate etc?

    We noticed that changing the inset/frame of the map while zooming the camera will:

    trigger uiView SafeAreaInsetChanged

    mapView.adjustContentInset

    which calls MGLMapView.cancelTransitions that also destroy the camera anmations

  20. 1ec5 commented on Aug 1, 2019

    @1ec5
    Contributor

    Would it be possible and is the idea to support animation for the camera and centerCoordinate etc?

    Yes, I think implicit animation of these properties is essentially what this issue tracks. There is a separate effort to overhaul the camera APIs on both Android and iOS/macOS, which is sort of tracked in #9808, but I think we have to solve this issue regardless, especially considering the prominence of implicit animation in SwiftUI.

  21. added
    MapKit parity
    on Aug 1, 2019
  22. changed the title [-]Animating map view contraints is jerky and does not update properly[/-] [+]Animating map view contraints is jerky; implicit animation via Core Animation properties not supported[/+] on Sep 10, 2019
  23. robert-frankin commented on Apr 17, 2020

    @robert-frankin

    Hi, I am getting same issue in iOS. Is there any solution to fix it? Please advise. @1ec5

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

    MapKit paritybuggl-iosiOS

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions