Reputation: 500
It's a flyover animation using UIMapKit
and basically animation begins with camera angle changing and after that spin around the object. I got error, and I don't know what's wrong. Please help.
"Pitch is the viewing angle of the camera, measured in degrees. A value of 0 results in a camera pointed straight down at the map. Angles greater than 0 result in a camera that is pitched toward the horizon by the specified number of degrees. If the map type is satellite or hybrid, the pitch value is clamped to 0.
The value in this property may be clamped to a maximum value to maintain map readability. There is no fixed maximum value, though, because the actual maximum value is dependent on the current altitude of the camera."
Now, the problem is, according to code below, I initialize the UIMapView
pitch value to 0. Down below, override func, when it's time for animation, I change the value to 65, so I expect the camera angle(pitch) would change, but when I run in the simulator, camera is still pointed straight down at the map. But the spin animation is working, because the heading between pitched camera and rotated camera has changed.
I don't know what's wrong with my pitch setting. Did I miss something? Should I add altitude property? Still try to figure that out.
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.
}
}
Upvotes: 0
Views: 171
Reputation: 500
I figured it out, turns out the iOS simulator doesn't support flyover. So when I run it on a real device, my beautiful flyover animation appears just like I expect.
Upvotes: 0