#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<CLLocationManagerDelegate>
@property(nonatomic,strong)CLLocationManager*manager;
@property (weak, nonatomic) IBOutlet UIImageView *imageW;
@end
@implementation ViewController
-(CLLocationManager*)manager
{
if (_manager==nil) {
_manager=[[CLLocationManager alloc]init];
}
return _manager;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.manager.delegate=self;
//判断ios7 或者8
if([[UIDevice currentDevice].systemVersion doubleValue]>8.0)
{
//[self.manager requestWhenInUseAuthorization];
[self.manager requestAlwaysAuthorization];
}
[self.manager stopUpdatingHeading];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
CGFloat angle=newHeading.magneticHeading*M_PI/180;
//旋转图片
self.imageW.transform =CGAffineTransformMakeRotation(-angle);
}
@end