当前位置: 动力学知识库 > 问答 > 编程问答 >

Get direction of device motion by using accelerometer in ios device

问题描述:

I want to get direction of the device motion by using accelerometer. I tried method suggested here as below :-

- (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler {

if (fabsf(aceler.x) > 1.5)

{

shake = YES;

NSTimeInterval myInterval = .75;

[NSTimer scheduledTimerWithTimeInterval:myInterval target:self selector:@selector(endShake) userInfo:nil repeats:NO];

return;

}

if(shake)

{

totalG += aceler.x;

}

}

- (void) endShake {

shake = NO;

int direction;

if (totalG isLessThan 0) direction = 1;

if(totalG isGreaterThan 0) direction = -1;

[self changePageByShake:direction];

totalG = 0;

}

But it's not giving accurate results. Is there any standard way to get the direction of the device ?

Note :- This is different from orientation of the device.

分享给朋友:
您可能感兴趣的文章:
随机阅读: