IOS加速度定位方向实例

作者:朱克锋

邮箱:[email protected]

转载请注明出处:http://blog.csdn.net/linux_zkf

IOS加速度定位方向实例

//要实现代理协议

@interface TestViewController : UIViewController <UIAccelerometerDelegate>

{

}

@end


@implementation TestViewController

//代理方法

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration

{

float xx = -[acceleration x];

float yy = [acceleration y];

float angle = atan2(yy, xx);

//NSLog or 相关处理

}

- (void) viewDidLoad

{

[[UIAccelerometer sharedAccelerometer] setDelegate:self];

}


你可能感兴趣的:(ios,float,interface)