开发者

Objective-C Using Accelerometer (iPhone)

开发者 https://www.devze.com 2022-12-26 21:12 出处:网络
I have a class called MainGame, which is defined like this in my .h: @interface MainGame : Renderer <UIAccelerometerDelegate>

I have a class called MainGame, which is defined like this in my .h:

@interface MainGame : Renderer <UIAccelerometerDelegate>

Then later in my .m I have this:

- (void) accelerometer: (UIAccelerometer *)a开发者_如何学运维ccelerometer didAccelerate: (UIAcceleration *)acceleration {
    // here I would read values like accelerometer.x
    NSLog(@"accelerated!!1");
}

Am I doing it right?

Currently I'm only testing in iPhone simulator, I'm going to buy the apple $99 developer thing soon. It doesn't log "accelerated!!1", but I'm guessing that's because I'm not running it on an actual device yet?


Correct. The iPhone simulator does not provide Accelerometer services.

You may find this useful: http://code.google.com/p/accelerometer-simulator/wiki/Home

There is also this, which allows you to use phone input in the simulator (warning, App Store link, also has a Lite version): http://itunes.com/app/iSimulate

0

精彩评论

暂无评论...
验证码 换一张
取 消