Objective-C 使用加速计 (iPhone)
我有一个名为 MainGame 的类,它在我的 .h 中定义如下:
@interface MainGame : Renderer <UIAccelerometerDelegate>
然后在我的 .m 中我有这样的:
- (void) accelerometer: (UIAccelerometer *)accelerometer didAccelerate: (UIAcceleration *)acceleration {
// here I would read values like accelerometer.x
NSLog(@"accelerated!!1");
}
我这样做对吗?
目前我只在 iPhone 模拟器中进行测试,我很快就会购买苹果 99 美元的开发者产品。它不会记录“加速!!1”,但我猜这是因为我还没有在实际设备上运行它?
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 *)accelerometer 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的。 iPhone模拟器不提供加速计服务。
您可能会发现这很有用:http://code.google.com/p/ accelerometer-simulator/wiki/Home
还有一个,它允许您在模拟器中使用手机输入(警告,App Store 链接,也有 Lite 版本):http://itunes.com/app/iSimulate
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