I watched a WWDC session on Apple Mapkit https://developer.apple.com/videos/play/wwdc2015/206/ I want to make a flyover animation showed at 31:33. Change camera angle from top to bottom and spin. But I wrote some code, it crushes. Please help me and tell me what's wrong with my code, thanks!
import UIKit
import CoreLocation
import MapKit
class Flyover: UIViewController, MKMapViewDelegate {
var coordinate = CLLocationCoordinate2D(latitude: 40.7484405, longitude: -73.9856644)
let distance : CLLocationDistance = 700
let pitch : CGFloat = 65
let heading = 90.0
var camera: MKMapCamera?
@IBOutlet var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView.mapType = .SatelliteFlyover
let camera = MKMapCamera(lookingAtCenterCoordinate: coordinate,fromDistance: distance,pitch: pitch,heading: heading)
mapView.camera = camera
//I want the animation to play automatically as soon as the user is in the view.
UIView.animateWithDuration(10.0, animations: {
self.camera!.heading += 180
self.camera!.pitch = 25
self.mapView.camera = self.camera!
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Aucun commentaire:
Enregistrer un commentaire