2016-04-19 56 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

相關問題