供应 供应信息
09 09 2021

IOS加速度传感器  我赢职场  在线教育

当前位置: 首页>IT设备、数码产品、软件 > 其他专用软件 > 实验室专用软件
来源:[北京沃赢科技有限公司]
联系人:刘女士
手机:15901097864
电话:010-82168774
传真:010-82168774
QQ:1350225154
Email:1350225154@qq.com
地址:北京北京市北京市海淀区
品牌:
价格:面议 元/
供应地:北京北京市
产品规格:

IOS加速度传感器(accelerometer)

简介
加速度传感器是根据x、y和z三个方向来检测在设备位置的改变。
通过加速度传感器可以知道当前设备相对于地面的位置。
以下实例代码需要在真实设备上运行,在模拟器上是无法工作的。
实例步骤
1、创建一个简单的视图应用程序
2、在ViewController.xib中添加三个标签,并创建一个ibOutlets分别为:xlable、ylabel和zlabel
3、如下所示,更新ViewController.h
#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UIAccelerometerDelegate>
{
    IBOutlet UILabel *xlabel;
    IBOutlet UILabel *ylabel;
    IBOutlet UILabel *zlabel;
}
@end
4、如下所示,更新ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIAccelerometer sharedAccelerometer]setDelegate:self];
    //Do any additional setup after loading the view,typically from a nib
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:
  (UIAcceleration *)acceleration{
    [xlabel setText:[NSString stringWithFormat:@"%f",acceleration.x]];
    [ylabel setText:[NSString stringWithFormat:@"%f",acceleration.y]];
    [zlabel setText:[NSString stringWithFormat:@"%f",acceleration.z]];
}
@end

学习链接:
http://www.wyzc.com/ios/?tg=5009295340
学习交流群:317140762

电话咨询获取底价