CLOSE SEARCH

Using Accelerometer

AccelerometerSample <- 샘플 프로젝트



– (void)viewDidLoad {
[super viewDidLoad];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.1f];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
}


– (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
xLabel.text = [NSString stringWithFormat:@”%f”, acceleration.x];
yLabel.text = [NSString stringWithFormat:@”%f”, acceleration.y];
zLabel.text = [NSString stringWithFormat:@”%f”, acceleration.z];
}


– (void)dealloc
{
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
[super dealloc];
}

Filed under: iOS