IOS 11 MKMapview changing zoom level when altering its frame or rotating
Asked Answered
T

2

7

I've a MKMapView that I expand and contract with code like this:

UIView.animate(withDuration: 0.5) {
   mapView.frame = CGRect(x: 0, y: 0, width: 200, height: 400)
}

Before IOS 11 the above code would trigger regionDidChangeAnimateddelegate method after animation was completed. It would change its region and let zoom level be.

In IOS 11 just the zoom changes. None of the delegate methods are triggered.

I need to have it like before. Changing maps frame should just make the visible area bigger without zoom change.

I've tried to set mapView.isZoomEnabled = false before altering mapViews frame, but the zoom level keeps changing.

Update:

I added two animated GIFs to compare IOS 11 with previous IOS versions.

IOS 11 will zoom in immediately before expand animation starts. It will zoom out after the reverse animation is completed.

As you see below the IOS 9 animation is smooth as silk.


IOS 11:

enter image description here


IOS 9:

enter image description here

Tipstaff answered 23/10, 2017 at 13:25 Comment(3)
Have you figured out a work around yet?Piety
@Piety No I never did. It's still an issue unfortunately.Tipstaff
Perhaps related to openradar.me/34120191Nitz
P
2

Found a solution! More of a hack:

Center the MapView on Y and give the MapView a fixed height, I used: UIScreen.main.bounds.size.height.

Piety answered 11/12, 2017 at 3:45 Comment(4)
I already give the MapView a fixed height. It's still zooming for me. Can you please give more details on your solution?Tipstaff
Place your mapView inside a UIView. Set the mapView's constraints: left, right, center Y, fixed height. Then animate the height of your UIView.Piety
So you set clipsToBounds to UIView and just show the part of the map which is within the bounds of it's superview. In my case this involves a lot of work since I got logic that cluster annotations based on MapView bounds. It's a really nice solution though!Tipstaff
What method from mapKit are you using to manage cluster? Could you use the UIView bounds in place of the mapView bounds?Piety
S
1

After attempting to create my own map view, and duplicating your GIFs, it appears that this is an issue in iOS 11. I've seen similar effects happens with other views in the past.

While it won't match what your iOS 9 GIF above shows, an alternative to changing the frame might be to change the transform property. The map will of course, shrink, but there will not be any visible artifacts as seen above.

Subirrigate answered 27/10, 2017 at 19:3 Comment(2)
I appreciate the workaround, but for me this isn't an option I think. Scaling map also makes annotations scale and look pixelated. Also the zoom effect isn't really working for me. But I'm starting to think you're right that this is the only solution for making the animation look smooth.Tipstaff
I'm not sure what your use case is for the footer, but another option is to not change the frame, but rather, move it up vertically while the footer is expanded. This only works best if its a temporary state of the UI like the keyboard growing from the bottom, other user input, etc.Subirrigate

© 2022 - 2024 — McMap. All rights reserved.