Skip to content

Instantly share code, notes, and snippets.

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 alexruperez/fcd0f523f14cdc5915d1 to your computer and use it in GitHub Desktop.
Save alexruperez/fcd0f523f14cdc5915d1 to your computer and use it in GitHub Desktop.
MKMapView extension with setVisibleMapAnnotations edgePadding animated helper in Swift
extension MKMapView
{
func setVisibleMapAnnotations(edgePadding: UIEdgeInsets, animated: Bool)
{
var zoomRect = MKMapRectNull
for annotationObject in annotations
{
let annotation = annotationObject as MKAnnotation
let annotationPoint = MKMapPointForCoordinate(annotation.coordinate)
let pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1)
if (MKMapRectIsNull(zoomRect))
{
zoomRect = pointRect
}
else
{
zoomRect = MKMapRectUnion(zoomRect, pointRect)
}
}
setVisibleMapRect(zoomRect, edgePadding: edgePadding, animated: animated)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment