在应用内使用原生iOS指南针

是否有可能在我的应用程序中使用iOS的本地指南针? 还是我需要绘制和制作我自己的指南针?

没有原生罗盘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);