iOS UIView.animatewithDuration in Swift 2.2?



这是使用UIMapKit的天桥动画,基本上动画始于摄像头角度,然后在对象周围旋转。我有错误,我不知道怎么了。请帮助。

" 音高是相机的视角,以度为单位。 a 值为0导致摄像机直接向下指向地图。 角度大于0的角度导致倾斜的相机 地平线按指定的度数数量。如果地图类型是 卫星或混合动力,螺距值夹紧至0。

该属性中的值可以夹紧到最大值 保持地图可读性。但是,没有固定的最大值 因为实际最大值取决于当前高度 相机。"

现在,根据下面的代码,我将UIMapView音高值初始化为0。下面,覆盖功能,当是时候进行动画时,我将值更改为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模拟器不支持天桥。因此,当我在真实的设备上运行它时,我的美丽的天桥动画就会像我期望的那样。

最新更新