IOS中陀螺仪的使用方法
作者:互联网
#import <CoreMotion/CoreMotion.h>
@property (strong) CMMotionManager *motionManager;
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_motionManager = [[CMMotionManager alloc]init];
_motionManager.gyroUpdateInterval = 0.1;
if(_motionManager.gyroAvailable) {
[_motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMGyroData *gyroData, NSError *error) {
printf("%lf, %lf, %lf\n", gyroData.rotationRate.x, gyroData.rotationRate.y, gyroData.rotationRate.z);
_glView.rotx -= gyroData.rotationRate.x/8;
_glView.roty -= gyroData.rotationRate.y/8;
}];
}
}
- (void) viewWillDisappear:(BOOL)animated
{
if(_motionManager.gyroActive)
[_motionManager stopGyroUpdates];
[super viewWillDisappear:animated];
}
Build Phases --> Link Binary With Libraries --> [+] --> CoreMotion.framework
标签:lf,陀螺仪,--,IOS,gyroData,rotationRate,animated,方法,motionManager 来源: https://blog.51cto.com/u_15298588/3034072