2012-02-13 28 views

回答

30

沒有天生的指南針UIView。爲了使用磁力計,你將不得不使用CoreLocation和下面的委託方法:

- (void) locationManager:(CLLocationManager *)manager 
      didUpdateHeading:(CLHeading *)newHeading 

轉動一個UIView指向北(bearingView是一個UIImageView):

float heading = newHeading.magneticHeading; //in degrees 
float headingDegrees = (heading*M_PI/180); //assuming needle points to top of iphone. convert to radians 
self.bearingView.transform = CGAffineTransformMakeRotation(headingDegrees); 
+0

是的,我認爲你對本地指南針UIView是正確的。我會稍等一下,看看是否有其他人不同意。當然是的,didUpdateHeading是更新我選擇繪製的任何圖像的方式。非常感謝。 – theDuncs 2012-02-13 18:07:53

+1

凱勒 - 因爲沒有人與你相矛盾,我會以你的答案爲準。謝了哥們。 – theDuncs 2012-02-20 15:53:33

+0

沒問題。要創建一個指向北方的羅盤視圖,只需創建一個「羅盤針」圖形並通過它的變換進行旋轉。看我的編輯。 – Keller 2012-02-21 01:25:04

相關問題