来自here,
我知道可以使用加速度计读数检测到Tap Pressure。但该链接中提供的代码已有3年历史,Apple已用CoreMotion取代了UIAccelerometer。 我有以下代码来测量三轴的加速度:
motionManager = [[CMMotionManager alloc]init];
motionManager.deviceMotionUpdateInterval = 1;
[motionManager startDeviceMotionUpdates];
timer = [NSTimer scheduledTimerWithTimeInterval:(1) target:self selector:@selector(read) userInfo:nil repeats:YES];
if([motionManager isGyroAvailable]){
if(![motionManager isGyroActive]){
[motionManager setGyroUpdateInterval:1.0];
[motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error){
accelerationX.text = [[NSString alloc]initWithFormat:@"%0.2f", gyroData.rotationRate.x ];
accelerationY.text = [[NSString alloc]initWithFormat:@"%0.2f", gyroData.rotationRate.y ];
accelerationZ.text = [[NSString alloc]initWithFormat:@"%0.2f", gyroData.rotationRate.z ];
}];
}
}
我有什么方法可以使用CoreMotion检测Tap Pressure?