我有一个问题。好吧,我为android设备做了一个应用程序。哪个返回我的值(value)
SensorManager sensorManager;
Sensor sensor;
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);with
public void onSensorChanged(SensorEvent event) {
xAxis = event.values[0];
zAxis = event.values[2];
}
好吧,我想了解一点 iOS 并为 iOS 系统制作这个程序。我怎样才能为 iOS 做这行?我搜索了一下,但并没有真正找到有用的东西。
线加速度 = Force/mass = (ax, ay, az),它是一个具有三个方向分量的向量
#import <CoreMotion/CoreMotion.h>
CMMotionManager *manager = [[CMMotionManager alloc] init];
if (manager.isAccelerometerAvailable) {
manager.accelerometerUpdateInterval = 0.01;
[manager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData * _Nullable accelerometerData, NSError * _Nullable error) {
if (accelerometerData != NULL) {
CMAcceleration acceleration = accelerometerData.acceleration;
double x_acceleration = acceleration.x;
double y_acceleration = acceleration.y;
double z_acceleration = acceleration.z;
double linear_acceleration = sqrt(pow(x_acceleration, 2) + pow(y_acceleration, 2) + pow(z_acceleration, 2));
NSLog(@"linear_acceleration: %@", linear_acceleration);
}
}];
}
UIAccelerometer
已弃用并被 CoreMotion
框架取代。
关于ios - iOS 上的线性加速如何获得与 Android TYPE_LINEAR_ACCELERATION 相同的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42203785/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |