//
// ViewController.m
// ZhiNanZhen
//
// Created by hq on 16/5/17.
// Copyright 2016年 hanqing. All rights reserved.
//
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController () <CLLocationManagerDelegate>
@property(nonatomic,strong) CLLocationManager *clm;
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@end
@implementation ViewController
-(CLLocationManager *)clm{
if (_clm==nil) {
_clm=[[CLLocationManager alloc] init];
_clm.delegate=self;
}
return _clm;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.clm startUpdatingHeading];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
/**
* magneticHeading 表示磁北极偏转的角度
*trueHeading 磁北极的真实角度
*0.0 - 359.9 度, 0 being true North
*/
NSLog(@"%f",newHeading.magneticHeading);
//将我们的角度转换为弧度
CGFloat angle=newHeading.magneticHeading/180.0*M_PI;
[UIView animateWithDuration:0.2 animations:^{
//旋转我们的指南针
self.imgView.transform=CGAffineTransformMakeRotation(-angle);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
startUpdatingHeading开发一个指北针
最新推荐文章于 2021-05-12 15:39:09 发布