I want to track the device's movement along X-axis in a straight line just like panorama.
I try with Accelerometer but can't able to track this.
I think it only detect the Device Rotation. I search a lot for the tutorial of Grayscope, Magnetometer, etc.
Any one can give the sample of the Core motion?
Help me to solve this.
Thank you.
My code is as follow:
- (void)viewDidLoad
{
[super viewDidLoad];
xval=0;
motionManager = [[CMMotionManager alloc] init];
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
NSOperationQueue *aQueue = [NSOperationQueue alloc];
[motionManager startDeviceMotionUpdatesToQueue:aQueue withHandler:^(CMDeviceMotion *motion, NSError *error) {
NSLog(@"X value is: %f", motion.userAcceleration.x);
if (motion.userAcceleration.x > 0.05) {
//a solid move forward starts
//lineLength++; //increment a line length value
xval=xval+10;
ball.frame=CGRectMake(xval, 361, 119, 104);
}
if (motion.userAcceleration.x < -0.02 ) {
[motionManager stopDeviceMotionUpdates];
}
}];
}