Skip to content

Instantly share code, notes, and snippets.

@ayaysir
Created February 11, 2023 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayaysir/65c9482b3c79afd665619d42055c766c to your computer and use it in GitHub Desktop.
Save ayaysir/65c9482b3c79afd665619d42055c766c to your computer and use it in GitHub Desktop.
[Swift] MKMapView에서 초기 로드시 지도 확대하기 / Delta: 줌 팩터 단위, 2는 2배 줌 아웃(멀어짐), 0.5는 2배 줌 인 (가까워짐)
extension MKMapView {
/**
``delta`` is the zoom factor
- 2 will zoom out x2
- .5 will zoom in by x2
*/
func setZoomByDelta(delta: Double, animated: Bool) {
var _region = region;
var _span = region.span;
_span.latitudeDelta *= delta;
_span.longitudeDelta *= delta;
_region.span = _span;
setRegion(_region, animated: animated)
}
}
/*
사용 예:
override func viewDidLoad() {
mapView.setZoomByDelta(delta: pow(2, -13), animated: true)
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment