在应用程序中使用原生iOS指南针

the*_*ncs 12 native objective-c ios compass-geolocation

是否可以使用iOS在我自己的应用程序中使用的原生指南针?或者我是否需要绘制自己的指南针并制作动画?

Kel*_*ler 30

没有原生指南针UIView.要使用磁力计,您必须使用CoreLocation和以下委托方法:

- (void) locationManager:(CLLocationManager *)manager
             didUpdateHeading:(CLHeading *)newHeading
Run Code Online (Sandbox Code Playgroud)

将UIView旋转到指向North(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);
Run Code Online (Sandbox Code Playgroud)

  • 如果有人想知道,这是一个关于如何实现这个的完整教程:http://blog.objectgraph.com/index.php/2012/01/10/how-to-create-a-compass-in-iphone/ (3认同)