2016-06-22 86 views
0

這是一個使用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. 
    } 

} 

回答

0

我想通了,原來的的iOS模擬器不支持天橋。所以當我在真實設備上運行它時,我的美麗天橋動畫就像我期望的一樣。

相關問題