linux 股票指南针,IOS开发入门之ios指南针

本文将带你了解IOS开发入门之ios指南针,希望本文对大家学IOS有所帮助

参考http://blog.sina.com.cn/s/blog_4a37054201013nhr.html

可运行的代码如下

1.拖拽ImageView ,关联变量到.h中

2.代码如下

//

//  ViewController.h

//  SouthDemo

//

//  Created by xiao7 on 14/10/25.

//  Copyright (c) 2014年 killinux. All rights reserved.

//

#import

#import

@interface ViewController : UIViewController

@property (strong, nonatomic) CLLocationManager *locationManager;

@property (strong, nonatomic) IBOutlet UIImageView *arrowImageView;

@end

[/code

Java代码  //  //  ViewController.m  //  SouthDemo  //  //  Created by xiao7 on 14/10/25.  //  Copyright (c) 2014年 killinux. All rights reserved.  //    #import "ViewController.h"      @interface ViewController ()    @end    @implementation ViewController      - (void)viewDidLoad {      [super viewDidLoad];      //NSLog(@"SourceDemo");      _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"compass.png"]];            _arrowImageView.center = CGPointMake(160, 240);            [self.view addSubview:_arrowImageView];      self.locationManager= [[CLLocationManager alloc]init];      self.locationManager.delegate = self;            if ([CLLocationManager headingAvailable]) {          //设置精度          self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;          //设置滤波器不工作          self.locationManager.headingFilter = kCLHeadingFilterNone;          //开始更新          [self.locationManager startUpdatingHeading];      }          }  -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading  {      NSLog(@"didUpdateHeading---->");      //每次要重置view的位置,才能保证图片每次偏转量正常,而不是叠加,指针方向正确。      _arrowImageView.transform = CGAffineTransformIdentity;            CGAffineTransform transform = CGAffineTransformMakeRotation(-1 * M_PI*newHeading.magneticHeading/180.0);                  //    CGAffineTransform transform = CGAffineTransformMakeTranslation(10, 50);      _arrowImageView.transform = transform;  }  - (void)didReceiveMemoryWarning {      [super didReceiveMemoryWarning];      // Dispose of any resources that can be recreated.  }    @end  //

//  ViewController.m

//  SouthDemo

//

//  Created by xiao7 on 14/10/25.

//  Copyright (c) 2014年 killinux. All   rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//NSLog(@"SourceDemo");

_arrowImageView = [[UIImageView   alloc] initWithImage:[UIImage imageNamed:@"compass.png"]];

_arrowImageView.center =   CGPointMake(160, 240);

[self.view   addSubview:_arrowImageView];

self.locationManager= [[CLLocationManager   alloc]init];

self.locationManager.delegate =   self;

if ([CLLocationManager   headingAvailable]) {

//设置精度

self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

//设置滤波器不工作

self.locationManager.headingFilter = kCLHeadingFilterNone;

//开始更新

[self.locationManager   startUpdatingHeading];

}

}

-(void)locationManager:(CLLocationManager *)manager   didUpdateHeading:(CLHeading *)newHeading

{

NSLog(@"didUpdateHeading---->");

//每次要重置view的位置,才能保证图片每次偏转量正常,而不是叠加,指针方向正确。

_arrowImageView.transform =   CGAffineTransformIdentity;

CGAffineTransform transform =   CGAffineTransformMakeRotation(-1 *   M_PI*newHeading.magneticHeading/180.0);

//    CGAffineTransform transform =   CGAffineTransformMakeTranslation(10, 50);

_arrowImageView.transform =   transform;

}

- (void)didReceiveMemoryWarning {

[super   didReceiveMemoryWarning];

// Dispose of any resources that   can be recreated.

}

@end

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之IOS频道!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值