【发布时间】:2016-06-22 01:20:43
【问题描述】:
这是一个使用UIMapKit 的天桥动画,基本上动画从摄像机角度变化开始,然后围绕对象旋转。我有错误,我不知道出了什么问题。请帮忙。
"俯仰是相机的视角,以度为单位。 A 值为 0 会导致相机直接指向地图。 大于 0 的角度会导致摄像机朝向 水平线按指定的度数。如果地图类型是 卫星或混合,音高值被限制为 0。
此属性中的值可能会被限制为最大值以 保持地图的可读性。但是,没有固定的最大值, 因为实际最大值取决于当前高度 相机。”
现在,问题是,根据下面的代码,我将UIMapView 的俯仰值初始化为 0。在下面,覆盖 func,当动画时,我将值更改为 65,所以我期望摄像机角度(音高)会改变,但是当我在模拟器中运行时,相机仍然直接指向地图。但是旋转动画可以正常工作,因为俯仰摄像机和旋转摄像机之间的航向发生了变化。
我不知道我的音高设置有什么问题。我错过了什么?我应该添加高度属性吗?还是想办法弄明白。
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.
}
}
【问题讨论】:
标签: ios swift swift2 xcode7 uiviewanimation