2016-06-21 8 views
0

私は高架道路アニメーションを作りたいアップルMapkit https://developer.apple.com/videos/play/wwdc2015/206/WWDCセッションを見ては31:33でした。カメラの角度を上から下に変えて回転させます。しかし、私はいくつかのコードを書いた、それはクラッシュします。私の助けを借りて、私のコードに間違っていることを教えてください、ありがとう!Apple Mapkitのフライオーバーをアニメーション化する方法は?

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. 
    } 
    */ 

} 
+0

Niravさんありがとうございましたか?私はあなたがプロのリンゴの開発者であることを見た –

+0

私はこれを試したことはありません私は答えを見つける場合私はそれを検索します私はここで答えを投稿します。 –

+0

ありがとうございます。 WWDCビデオにはソースコードがありますが、それはOS X向けです。 –

答えて

0

あなたはほぼそこにいました。新しいカメラを作ってみてください。

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) 
関連する問題