Hi I'm new to stack overflow, and to iOS applicationprogramming. I've learnt basic-intermediate Objective C coding and have done bits and pieces to do with actual iOS apps, but have not actually published one to the App Store yet.
The first one I'm interested in doing I just a basic app using the accelerometer. I want to make an app where there is a ruler on the iPhone's screen and you can move it along a flat object and in the end it will give you the length of it. I have read through the iOS documentation regarding the accerometer, but I don't know how to apply it to give me the distance of something...
Any help like links to read through, or code excerpts, or an open source app like it would be much appreciated!
Do you remember physics from school? Newton's laws of motion?
velocity = distance/time
so:
distance = velocity x time.
Acceleration is the change in velocity over time right? You do the rest...
Anyway, less rubbish, here's the Objective-C:
You'll need to conform to <UIAccelerometerDelegate>
then you can:
-(void)startMeasuringAcceleration{
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.125];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
}
-(void)stopMeasuringAcceleration{
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
}
//this is a delegate method
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
NSLog(@"%f, %f, %f, %f", acceleration.x, acceleration.y, acceleration.z, acceleration.timestamp);
}