成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

[IOS]陀螺儀和加速儀編程

如何實現(xiàn)iPhone的重力感應(yīng)還有旋轉(zhuǎn)感應(yīng),也就是術(shù)語上的陀螺儀和加速器?下面我們來用一個簡單的Demo入門一下吧!

由于模擬器上不能運行這個,所以只能貼出代碼,沒有截圖。

ViewController.h:

創(chuàng)新互聯(lián)建站從2013年成立,先為昌江黎族等服務(wù)建站,昌江黎族等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為昌江黎族企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

#import <UIKit/UIKit.h> @interface BIDViewController : UIViewController<UIAccelerometerDelegate> @property (weak, nonatomic) IBOutlet UILabel *accelerometerLabel; @property (weak, nonatomic) IBOutlet UILabel *gyroscopeLabel; @end

ViewController.m:

#import "BIDViewController.h" #import <CoreMotion/CoreMotion.h>  @interface BIDViewController () @property (strong, nonatomic) CMMotionManager *motionManager; @property (strong, nonatomic) NSOperationQueue *queue; @end  @implementation BIDViewController  - (NSUInteger)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskPortrait; }  - (void)viewDidLoad {     [super viewDidLoad]; 	// Do any additional setup after loading the view, typically from a nib.          self.motionManager = [[CMMotionManager alloc] init];     self.queue = [[NSOperationQueue alloc] init];          if (self.motionManager.accelerometerAvailable) {                  self.motionManager.accelerometerUpdateInterval = 1.0 / 10.0;                  [self.motionManager startAccelerometerUpdatesToQueue:self.queue                                                  withHandler:          ^(CMAccelerometerData *accelerometerData, NSError *error) {                           NSString *labelText;             labelText = [NSString stringWithFormat:                         @"Accelerometer\n-----------\nx: %+.2f\ny: %+.2f\nz: %+.2f",                         accelerometerData.acceleration.x,                         accelerometerData.acceleration.y,                         accelerometerData.acceleration.z];              NSLog(@"%@",labelText);           }];     } else {         self.accelerometerLabel.text = @"This device has no accelerometer.";     }     if (self.motionManager.gyroAvailable) {         self.motionManager.gyroUpdateInterval = 1.0 / 10.0;         [self.motionManager startGyroUpdatesToQueue:self.queue withHandler:          ^(CMGyroData *gyroData, NSError *error) {                            NSString *labelText;             labelText = [NSString stringWithFormat:                         @"Gyroscope\n--------\nx: %+.2f\ny: %+.2f\nz: %+.2f",                         gyroData.rotationRate.x,                         gyroData.rotationRate.y,                         gyroData.rotationRate.z];              NSLog(@"%@",labelText);           }];     } else {         self.gyroscopeLabel.text = @"This device has no gyroscope";     } }   @end

切記要導(dǎo)入CoreMotion.framework框架

本文題目:[IOS]陀螺儀和加速儀編程
網(wǎng)站網(wǎng)址:http://jinyejixie.com/article6/poesog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、網(wǎng)站維護(hù)、品牌網(wǎng)站制作網(wǎng)站收錄、微信小程序全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管
逊克县| 扶余县| 共和县| 孟村| 金湖县| 驻马店市| 天等县| 望城县| 綦江县| 和平区| 宁城县| 喀喇| 元朗区| 哈巴河县| 哈巴河县| 碌曲县| 罗平县| 阜南县| 普洱| 雷山县| 福建省| 民乐县| 靖安县| 东源县| 东港市| 高州市| 岳普湖县| 黄石市| 鸡泽县| 徐州市| 宁津县| 望谟县| 贵州省| 会理县| 田阳县| 华蓥市| 徐闻县| 盐城市| 霍邱县| 南昌县| 平定县|