iOS UIView.animatewithDuration 在 Swift 2.2 中?
iOS UIView.animatewithDuration in Swift 2.2?
这是一个使用 UIMapKit
的天桥动画,基本上动画从摄像机角度变化开始,然后围绕对象旋转。我得到了错误,我不知道出了什么问题。请帮忙。
"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."
现在,问题是,根据下面的代码,我将 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 模拟器不支持天桥。因此,当我 运行 在真实设备上使用它时,我美丽的天桥动画出现了,就像我期望的那样。
这是一个使用 UIMapKit
的天桥动画,基本上动画从摄像机角度变化开始,然后围绕对象旋转。我得到了错误,我不知道出了什么问题。请帮忙。
"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."
现在,问题是,根据下面的代码,我将 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 模拟器不支持天桥。因此,当我 运行 在真实设备上使用它时,我美丽的天桥动画出现了,就像我期望的那样。