gpt4 book ai didi

Swift 2.2 中的 iOS UIView.animatewithDuration?

转载 作者:行者123 更新时间:2023-11-30 13:18:53 25 4
gpt4 key购买 nike

这是一个使用 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的pitch值初始化为0。在下面,覆盖func,当动画时间到时,我将值更改为65,所以我预计相机角度(俯仰)会改变,但是当我在模拟器中运行时,相机仍然垂直向下指向 map 。但是旋转动画正在工作,因为倾斜相机和旋转相机之间的航向已经改变。

我不知道我的音调设置出了什么问题。我错过了什么?我应该添加海拔属性吗?仍然尝试弄清楚这一点。

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模拟器不支持flyover。因此,当我在真实设备上运行它时,美丽的飞越动画就像我期望的那样出现。

关于Swift 2.2 中的 iOS UIView.animatewithDuration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37957054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com