Is it possible to use the native compass that iOS has within my own application? Or do I need to draw and animate my own compass?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There is no native compass UIView
. In order to use the magnetometer, you'll have to use CoreLocation and the following delegate method:
- (void) locationManager:(CLLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading
to rotate a UIView to point North (bearingView is a 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);