iOS 指南针的制作 附带源码
2013-06-28 20:14
211 查看
iOS 指南针的制作 附带源码
代码下载地址: http://pan.baidu.com/share/link?shareid=3088506835&uk=3189484501
指南针的制作非常简单。
直接看代码吧!
需要添加
<CoreLocation/CoreLocation.h>框架
ViewController.h代码如下:
ViewController.m代码如下:
这样就OK啦 ! 要在真机上测试哦!!!
代码下载地址: http://pan.baidu.com/share/link?shareid=3088506835&uk=3189484501
指南针的制作非常简单。
直接看代码吧!
需要添加
<CoreLocation/CoreLocation.h>框架
ViewController.h代码如下:
#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface ViewController : UIViewController<CLLocationManagerDelegate> @property (retain, nonatomic) UIImageView *compassImageView; @property (retain, nonatomic) CLLocationManager *locationManager; @end
ViewController.m代码如下:
- (void)viewDidLoad { [super viewDidLoad]; UIImageView* backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BackGroundPad.png"]]; [self.view addSubview:backgroundImage]; //创建指南针图片 self.compassImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Compass_HD.png"]]; self.compassImageView.center = CGPointMake(370, 500); [self.view addSubview:self.compassImageView]; //初始化locationManager并设置代理类 self.locationManager = [[CLLocationManager alloc]init]; self.locationManager.delegate = self; if ([CLLocationManager headingAvailable]) { //设置精度 self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; //设置滤波器不工作 self.locationManager.headingFilter = kCLHeadingFilterNone; //开始更新 [self.locationManager startUpdatingHeading]; } else { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"atention" message:@"compass not Available" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; } }
//调用locationManager成员方法 - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { //重置view的位置 self.compassImageView.transform = CGAffineTransformIdentity; CGAffineTransform transform = CGAffineTransformMakeRotation(-1 * M_PI*newHeading.magneticHeading/180.0); self.compassImageView.transform = transform; }
这样就OK啦 ! 要在真机上测试哦!!!
相关文章推荐
- iOS 指南针的制作 附带源码
- iOS 指南针的制作 附带源码
- Silverlight实用窍门系列:28.Silverlight制作随机分布雷达扫描点,模拟雷达扫描图之被扫描设备【附带源码实例】
- ((ios开发学习笔记 十三))实现九宫格效果(附带源码)
- 基于ios开发点餐系统应用(附带源码)
- Silverlight实用窍门系列:39.Silverlight中使用Frame和Page控件制作导航【附带实例源码】
- IOS通知(附带漂亮时钟制作)
- iOS开发-博客导出工具开发教程(附带源码)
- Silverlight实用窍门系列:39.Silverlight中使用Frame和Page控件制作导航【附带实例源码】
- 基于ios开发点餐系统应用(附带源码)
- iOS开发-博客导出工具开发教程(附带源码)
- iOS开发-博客导出工具开发教程(附带源码)
- iOS开发-博客导出工具开发教程(附带源码)
- 基于ios开发点餐系统应用(附带源码)
- ios球体弹跳游戏源码
- iOS 合并.a文件,制作通用静态库
- java swing mysql实现的ktv点歌系统项目源码附带视频教程
- iOS framework制作 带你走出那些坑
- 猫猫学iOS 之广告轮播图,collectionView制作(源码)
- 打地鼠游戏iOS源码项目