2016-04-19 54 views
0

我有这段代码,它给我和Cannot convert value of type 'CLLocationDirection' (aka 'Double') to expected argument type 'Float'上的arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(direction)))。请帮我修复。谢谢。无法将类型'CLLocationDirection'(又名'Double')的值转换为预期参数类型'Float'

func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { 

var direction: CLLocationDirection = newHeading.magneticHeading 

if direction > 180 { 
    direction = 360 - direction 
} 
else { 
    direction = 0 - direction 
} 

// Rotate the arrow image 
if let arrowImageView = self.arrowImageView { 
    UIView.animateWithDuration(1.0, animations: {() -> Void in 
    arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(direction))) 

    }) 

而且还有可能使指南针指向由用户指定的经度和纬度吗?你能教我怎么做。非常感谢。

+0

强权即那么对于Radadians来说,这个度数是否会达到Float?如果这样self.degreesToRadians(浮动(方向))可能会做的伎俩。 –

+0

这样做了工作伴侣。谢谢。关于我的第二个问题。是否可以使指南针指向由用户指定的经度和纬度?你能教我怎么做。 – Dze

回答

3

斯威夫特的基本类型是不能互换(不像在Objective-C)

要么你让你的degreesToRadians功能也顺应Double
或者你必须创建一个Floatdirection

arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(CGFloat(direction)))) 
+0

谢谢它已经修复。另一件事,是否有可能使指南针指向由用户指定的经度和纬度?你能教我怎么样 – Dze

+0

对不起,我不熟悉CoreLocation – vadian

相关问题