This example shows how use accelerometer in iPhone.
1. Code for .h file.#import
@interface AccelerometerExampleViewController : UIViewController
UISlider *slider;
}
@end
2. Code for .m file.
#import "AccelerometerExampleViewController.h"
@implementation AccelerometerExampleViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.updateInterval = 0.05f;
accel.delegate = self;
slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 200, 300, 20)];
slider.minimumValue = -1;
slider.maximumValue = 1;
[self.view addSubview:slider];
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
NSLog(@"(%.02f, %.02f, %.02f)", acceleration.x, acceleration.y, acceleration.z);
slider.value = acceleration.x;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[slider release];
[super dealloc];
}
@end
You have made a very good post for .h & .m files, by providing the source code download link. Really useful to use the accelerometer in iPhone.
ReplyDeleteDownload Shame Alarm iPhone App
yes
ReplyDeleteit is usefull and steps and very good.
thanks for sharing this info.
have you created some social media applications ?
if yes so please let me know that how can i do my self ?
Thanks guys, for sharing this conductive accumulation.
ReplyDeletediscover more jailbreaking
Very Nice tutorial.....
ReplyDeleteRajesh
-------------------
ReplyDeleteYour contents are too simple to read and easy to understand.
--------------------------------
iPhone App Development And
iOS App Development
Very useful article for all iPhone app developer. I am sharing this article for friends also. Thanks
ReplyDeleteenterprise social mobility, enterprise mobile apps