您好,歡迎來(lái)到商國(guó)互聯(lián)![ 登陸 ] [ 免費(fèi)注冊(cè) ] [ 密碼找回 ]
當(dāng)前位置:商國(guó)互聯(lián)首頁(yè) 供應(yīng)信息 IT設(shè)備、數(shù)碼產(chǎn)品、軟件 其他專用軟件 實(shí)驗(yàn)室專用軟件

IOS加速度傳感器
IOS加速度傳感器(accelerometer)
簡(jiǎn)介
學(xué)習(xí)鏈接:
加速度傳感器是根據(jù)x、y和z三個(gè)方向來(lái)檢測(cè)在設(shè)備位置的改變。
通過(guò)加速度傳感器可以知道當(dāng)前設(shè)備相對(duì)于地面的位置。
以下實(shí)例代碼需要在真實(shí)設(shè)備上運(yùn)行,在模擬器上是無(wú)法工作的。
實(shí)例步驟
1、創(chuàng)建一個(gè)簡(jiǎn)單的視圖應(yīng)用程序
2、在ViewController.xib中添加三個(gè)標(biāo)簽,并創(chuàng)建一個(gè)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
學(xué)習(xí)交流群:317140762
聯(lián)系人:劉老師(市場(chǎng)部職員)
手機(jī):15901097864
郵箱:1350225154@qq.com
*您的姓名:
*聯(lián)系手機(jī):
固話電話:
E-mail:
所在單位:
需求數(shù)量:
*咨詢內(nèi)容: