MKZoomLevel is an implementation of zoom level getter & setter for MKMapView that works exactly the same as the private _zoomLevel
property without resetting the camera angle.
- It returns exactly the same value as the internal
_zoomLevel
value as well as when the orientation or the angle is changed, which is in theMKMapView
’s private API. - It preserves the value of
heading
andpitch
of thecamera
property for a new zoom level as they are, rather than resetting the camera angle. - It returns the latest zoom level even when the animation of region change is not finished, in contrast with the
camera
property.
import MapKit
import MKZoomLevel
let mapView = MKMapView()
// Get the zoom level
mapView.zoomLevel
// Set the zoom level
mapView.zoomLevel = 16.0
// Set the zoom level with an animation
mapView.setZoomLevel(16.0, animated: true)
Add this repository as a dependency in your Package.swift
:
// swift-tools-version:5.0
import PackageDescription
let package = Package(
...,
dependencies: [
.package(url: "https://github.com/stleamist/MKZoomLevel.git", .upToNextMajor(from: "1.2.0"))
],
...
)
Select File > Swift Packages > Add Package Dependency, then enter the following URL:
https://github.com/stleamist/MKZoomLevel.git
For more details, see Adding Package Dependencies to Your App.
MKZoomLevel is released under the MIT license. See LICENSE for details.