gpt4 book ai didi

ios - UIKit swift 5 : Set UIView Rotation Angle

转载 作者:行者123 更新时间:2023-12-01 16:11:45 24 4
gpt4 key购买 nike

我正在构建一个具有罗盘功能和一些附加功能的应用程序。我的目标是根据真北方向旋转罗盘 UIImageView

是否可以为图像设置特定的旋转角度(如在 Photoshop 或 Figma 中)而不是将其旋转一定量?

我目前的实现是这样的:

    func rotate(view: UIView, radians: Double) {
UIView.animate(withDuration: 0.5) {
view.transform = view.transform.rotated(by: CGFloat(radians))
}
}
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
let newRad = deg2rad(newHeading.trueHeading)
rotate(view: compassImageView, radians: compassRad-newRad)
compassRad = newRad
}

我希望做点什么:

compassImageView.layer.setRotationAngle(radians: newHeading.trueHeading)

有这样的东西吗?

最佳答案

如果我没理解错的话,你想要:

func rotate(view: UIView, to angle: Double) {
UIView.animate(withDuration: 0.5) {
view.transform = CGAffineTransform(rotationAngle: angle)
}
}
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
let newRad = deg2rad(newHeading.trueHeading)
rotate(view: compassImageView, to: newRad)
compassRad = newRad
}

或者它可能是 -newRad,这取决于这些角度的走向,我永远不记得了:)

关于ios - UIKit swift 5 : Set UIView Rotation Angle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62753825/

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