我在Apple上观看了WWDC会议
https://developer.apple.com/videos/play/wwdc2015/206/
我想制作一个31:33的天桥动画。从上到下改变相机角度并旋转。但是我写了一些代码,它崩溃了。请帮帮我,告诉我我的代码有什么问题,谢谢!
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.
}
*/
}
最佳答案
你就快到了。试着做一个像这样的新相机。
mapView.camera = MKMapCamera(lookingAtCenter: pinLocation, fromDistance: 2000, pitch: 0, heading: 0)
let pinLocation = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
let rotationCamera = MKMapCamera(lookingAtCenter: pinLocation, fromDistance: 2000, pitch: 75, heading: 180)
UIView.animate(withDuration: 10, delay: 0, options: .curveEaseInOut, animations: {
self.mapView.camera = rotationCamera
}, completion: nil)
关于ios - 如何为Apple Mapkit天桥设置动画?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37937397/