这是一个使用UIMapKit
的天桥动画,基本上动画从摄像机角度变化开始,然后在物体上旋转。我得到错误,我不知道什么是错的。请帮忙。iOS UIView.animatewithDuration在Swift 2.2中?
“节距是摄像机的视角,以度为单位。 0导致摄像机A 值指出直下地图。 角度大于0结果在照相机中被投朝向 地平线通过的程度的指定的号码。如果地图类型是 卫星或混合,间距值被钳位为0
在该属性的值可以被钳位到一个最大值 保持地图的可读性。虽然没有固定的最大值,但是, 因为实际最大值取决于相机的当前海拔高度 。“
现在的问题是,根据下面的代码,我初始化UIMapView
间距值设置为0楼下,覆盖FUNC,当它的时候的动画,我将值更改为65,所以我希望相机角度(pitch)会发生变化,但是当我在模拟器中运行时,摄像机仍然直接指向地图。但是旋转动画正在工作,因为倾斜相机和旋转相机之间的标题已经改变。
我不知道我的音高设置有什么问题。我错过了什么?我应该添加高度属性吗?仍然试图弄清楚。
https://developer.apple.com/reference/mapkit/mkmapcamera
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
let distance: CLLocationDistance = 700
let pitch: CGFloat = 65
let heading = 90.0
var camera = MKMapCamera()
let coordinate = CLLocationCoordinate2D(latitude: 40.7484405,
longitude: -73.9856644)
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView.mapType = .SatelliteFlyover
camera = = MKMapCamera(lookingAtCenterCoordinate: coordinate,
fromDistance: distance,
pitch: 0,
heading: 0)
self.mapView.camera = camera
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(animated: Bool) {
let pitchedCamera = MKMapCamera(lookingAtCenterCoordinate: coordinate, fromDistance: distance, pitch: pitch, heading: 0)
let rotatedCamera = MKMapCamera(lookingAtCenterCoordinate: coordinate, fromDistance: distance, pitch: pitch, heading: 180)
UIView.animateWithDuration(5.0, animations: {
self.mapView.camera = pitchedCamera
}, completion: {
(Completed: Bool) -> Void in
UIView.animateWithDuration(25.0, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {
self.mapView.camera = rotatedCamera
}, completion: nil)
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}