在应用程序中使用原生iOS指南针 [英] Use native iOS compass within an app

查看:149
本文介绍了在应用程序中使用原生iOS指南针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

没有原生指南针 UIView 。为了使用磁力计,你必须使用CoreLocation和以下委托方法:

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

将UIView旋转到point North(bearingView是一个UIImageView):

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

这篇关于在应用程序中使用原生iOS指南针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆