gpt4 book ai didi

iOS - MapKit 相机旋转动画

转载 作者:行者123 更新时间:2023-11-28 06:17:45 27 4
gpt4 key购买 nike

我正在尝试在 MapKit 上制作一些花哨的旋转(带间距)动画。使用此代码

func animateCamera() {
let newCamera: MKMapCamera? = mapView.camera
newCamera?.pitch = 90.0
newCamera?.heading = 180.0
newCamera?.altitude = 200.0

let camera: MKMapCamera? = mapView.camera
camera?.pitch = 0.0
camera?.heading = 360.0
camera?.altitude = 20.0

UIView.animate(withDuration: 3.0, delay: 0.0, options: ([.curveLinear, .beginFromCurrentState]), animations: {() -> Void in
self.mapView.setCamera(newCamera!, animated: true);
}, completion: {(_ finished: Bool) -> Void in
print("has not been interrupted : \(finished)")
})

UIView.animate(withDuration: 3.0, delay: 3.0, options: ([.curveLinear, .beginFromCurrentState]), animations: {() -> Void in
self.mapView.setCamera(camera!, animated: true);
}, completion: {(_ finished: Bool) -> Void in
print("has not been interrupted : \(finished)")
})
}

但是当我运行该函数时,它只会捕捉到给定的航向、俯仰和高度,而不会设置动画。我错过了什么或做错了什么?

提前致谢!

最佳答案

我知道必须有更好的方法来做到这一点,但这是我找到的方法,并且有效,主要问题是知道动画何时结束,我没有找到任何线索,所以我用2秒作为任意时间

func animateCamera() {
let newCamera: MKMapCamera = MKMapCamera(lookingAtCenter: self.mapView.camera.centerCoordinate, fromDistance: 200.0, pitch: 90.0, heading: 180.0)
self.mapView.setCamera(newCamera, animated: true)

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(2 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) {
let newCamera: MKMapCamera = MKMapCamera(lookingAtCenter: self.mapView.camera.centerCoordinate, fromDistance: 20.0, pitch: 0.0, heading: 360.0)
self.mapView.setCamera(newCamera, animated: true)
}
}

希望对你有帮助

关于iOS - MapKit 相机旋转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44664854/

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