startUpdatingHeading开发一个指北针

来源:互联网 发布:淘宝卖家开通直播 编辑:程序博客网 时间:2024/05/28 23:12
////  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

0 0
原创粉丝点击