Use native iOS compass within an app

纵然是瞬间 提交于 2019-12-18 15:09:50

问题


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);


来源:https://stackoverflow.com/questions/9264838/use-native-ios-compass-within-an-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!