Skip to content

Instantly share code, notes, and snippets.

@KyleGoslan
Last active March 21, 2016 00:06
Show Gist options
  • Save KyleGoslan/f0894fba0a7685516d0e to your computer and use it in GitHub Desktop.
Save KyleGoslan/f0894fba0a7685516d0e to your computer and use it in GitHub Desktop.
Animate MKMapCamera in Swift 2
//Create a new MKMapCamera object.
//Looking at, is where you want it to look at, in this example I keep it the same so use the map views current center coordinate
//I up the altitude (zoom out) by adding 1600 on to the current position
//Pitch and heading are the rotation and angle of the camera
let newCameraPosition = MKMapCamera(lookingAtCenterCoordinate: mapView.centerCoordinate, fromDistance: mapView.camera.altitude + 1600, pitch: 50, heading: -30)
//Animate the camera, here over 5 seconds with a 1.5 second delay, the options are fairly self explanitory.
UIView.animateWithDuration(5, delay: 1.5, options: [.AllowUserInteraction, .CurveEaseInOut], animations: {
self.mapView.camera = newCameraPosition
}) { success in
//Animation completed...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment