Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将double类型转换为CGAffineTransform?_Ios_Swift - Fatal编程技术网

Ios 如何将double类型转换为CGAffineTransform?

Ios 如何将double类型转换为CGAffineTransform?,ios,swift,Ios,Swift,旋转图像视图时: func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { imageView?.transform = newHeading.trueHeading } 我得到以下错误: 无法将类型“CLLocationDirection”(也称为“Double”)的值分配给类型“CGAffineTransform” 如何转换/分配它 更新: 一切正常,但

旋转图像视图时:

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
    imageView?.transform = newHeading.trueHeading

}
我得到以下错误:

无法将类型“CLLocationDirection”(也称为“Double”)的值分配给类型“CGAffineTransform”

如何转换/分配它

更新:

一切正常,但当我在模拟器中运行我的应用程序时(我没有任何iOS设备),我的imageview不会在正北方向旋转

为什么?


trueHeading
类型为
Double
,单位为度

要旋转
UIImageView
,必须提供转换:

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading)
{
    imageView?.transform = CGAffineTransform(rotationAngle: CGFloat(newHeading.trueHeading  * .pi / 180))
    // converting the value from degrees to radians, which CGAffineTransform expects.
}

你想在这里干什么?是否要旋转图像视图?是@rmaddy我想在旋转设备时旋转图像视图
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading)
{
    imageView?.transform = CGAffineTransform(rotationAngle: CGFloat(newHeading.trueHeading  * .pi / 180))
    // converting the value from degrees to radians, which CGAffineTransform expects.
}