指南针小demo
(1)设置背景图片,设置指南针背景图.
//背景图片
UIImageView* backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BackGroundPad.png"]];
[self.view addSubview:backgroundImage];
//创建指南针图片
self.compassImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"compass.png"]];
self.compassImageView.center = CGPointMake(160 , 240);
[self.view addSubview:self.compassImageView];
(2)初始化位置管理器
指南针的使用离不开位置管理器,需要使用CLLocationManager,
<pre name="code" class="objc"> //初始化locationManager并设置代理类
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
如果设备的探测器正常开启,则进行指南针相关设置,否则弹出alertView,进行提示探测器无法使用.代码如下: