Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 651
Toydor Avatar asked Oct 23 '17 13:10

Toydor


People also ask

How do you get zoom level in MKMapView?

The easiest way to get an Integer of the current zoom level, is by using the MapView function: regionDidChangeAnimated. This function recognizes every change in zoom and will give you the basis for the calculation of the zoom factor.

What is MKMapView?

The MKMapView class supports the ability to annotate the map with custom information. Because a map may have large numbers of annotations, map views differentiate between the annotation objects used to manage the annotation data and the view objects for presenting that data on the map.


1 Answers

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.

like image 198
Justin Avatar answered Nov 15 '22 03:11

Justin