IOS的重力传感器对应值的大小。

来源:互联网 发布:sql load data 编辑:程序博客网 时间:2024/06/05 06:08
2014-10-27 14:47:10.768 Web[4251:1688417] X:0.220245
2014-10-27 14:47:10.768 Web[4251:1688417] Y:0.507889
2014-10-27 14:47:10.768 Web[4251:1688417] Z:0.973267
2014-10-27 14:47:10.768 Web[4251:1688417] ===============
2014-10-27 14:47:10.797 Web[4251:1688417] X:0.208801
2014-10-27 14:47:10.798 Web[4251:1688417] Y:0.522568
2014-10-27 14:47:10.798 Web[4251:1688417] Z:1.002319
2014-10-27 14:47:10.798 Web[4251:1688417] ===============
2014-10-27 14:47:10.828 Web[4251:1688417] X:0.123505
2014-10-27 14:47:10.828 Web[4251:1688417] Y:0.465378
2014-10-27 14:47:10.828 Web[4251:1688417] Z:0.963242
2014-10-27 14:47:10.828 Web[4251:1688417] ===============
2014-10-27 14:47:10.865 Web[4251:1688417] X:0.004059
2014-10-27 14:47:10.866 Web[4251:1688417] Y:0.398056
2014-10-27 14:47:10.866 Web[4251:1688417] Z:0.744217
2014-10-27 14:47:10.866 Web[4251:1688417] ===============
2014-10-27 14:47:10.896 Web[4251:1688417] X:0.083084
2014-10-27 14:47:10.896 Web[4251:1688417] Y:0.452621
2014-10-27 14:47:10.896 Web[4251:1688417] Z:0.583801
2014-10-27 14:47:10.896 Web[4251:1688417] ===============
2014-10-27 14:47:10.935 Web[4251:1688417] X:0.224747
2014-10-27 14:47:10.935 Web[4251:1688417] Y:0.410202
2014-10-27 14:47:10.935 Web[4251:1688417] Z:0.946533
2014-10-27 14:47:10.935 Web[4251:1688417] ===============




跑起来以后值不停的变化。本人是第一次做重力的。听安卓同事说xyz的值范围是 -10~10  , 我感觉我这个是不是不对。放在桌子上不动也在变。而且值还这么小。下面是代码。


 UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
    accelerometer.delegate =self;
    accelerometer.updateInterval =1.0/30.0f;



-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    static NSInteger shakeCount = 0;
    
    static NSDate *shakeStart;
    
    NSDate *now = [[NSDate alloc]init];
    
    NSDate *checkDate = [[NSDate alloc]initWithTimeInterval:3.0f sinceDate:shakeStart];
    
    if ([now compare:checkDate] == NSOrderedDescending || shakeStart == nil) {
        shakeCount =0;
        shakeStart = [[NSDate alloc]init];
    }
_Lblx.text = [NSString stringWithFormat:@"%f",fabsf(acceleration.x)];
    _Lbly.text = [NSString stringWithFormat:@"%f",fabsf(acceleration.y)];
    _Lblz.text = [NSString stringWithFormat:@"%f",fabsf(acceleration.z)];
    NSLog(@"X:%@",_Lblx.text);
    NSLog(@"Y:%@",_Lbly.text);
    NSLog(@"Z:%@",_Lblz.text);
    NSLog(@"===============");
    if (fabsf(acceleration.x)>1.7||
        fabsf(acceleration.y)>1.7||
        fabsf(acceleration.z)>1.7) {
        shakeCount ++;
        if (shakeCount >4) {
            NSLog(@"摇晃中.");
            shakeCount =0;
            shakeStart = [[NSDate alloc]init];
        }
    }
}
0 0
原创粉丝点击