加速度计适用于 iphone/ipad 模拟器吗?

发布于 2024-08-30 21:28:29 字数 1109 浏览 5 评论 0原文

据我所知,当我在 XCode 中使用 iPad 模拟器时,我的应用程序应该会触发加速计事件,但事实并非如此。

我用谷歌搜索了一下,似乎加速度计没有在模拟器中实现,这是正确的吗?如果是这样,为什么他们会有“硬件->摇动手势”菜单选项?

我的代码如下:

.h 文件:

@interface MyViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UIAccelerometerDelegate>{
    UIAccelerometer *accelerometer;
    //...other stuff
}
@property (nonatomic, retain) UIAccelerometer *accelerometer;
@end

然后 .m 文件:

@implementation MyViewController
@synthesize accelerometer;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"X: ", acceleration.x]);
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"Y: ", acceleration.y]);
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"Z: ", acceleration.z]);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.accelerometer = [UIAccelerometer sharedAccelerometer];
    self.accelerometer.updateInterval = .1;
    self.accelerometer.delegate = self;
}
@end

这看起来正确吗?

From what I can tell, my app should be firing accelerometer events while Im using the iPad simulator in XCode, but its not.

I have googled around and it somewhat seems that the accelerometer is not implemented in the simulator, is this correct? If so, why on earth would they have a "Hardware->Shake Gesture" menu option?

My code is as follows:

.h file:

@interface MyViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UIAccelerometerDelegate>{
    UIAccelerometer *accelerometer;
    //...other stuff
}
@property (nonatomic, retain) UIAccelerometer *accelerometer;
@end

then the .m file:

@implementation MyViewController
@synthesize accelerometer;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"X: ", acceleration.x]);
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"Y: ", acceleration.y]);
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"Z: ", acceleration.z]);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.accelerometer = [UIAccelerometer sharedAccelerometer];
    self.accelerometer.updateInterval = .1;
    self.accelerometer.delegate = self;
}
@end

Does this look right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦与时光遇 2024-09-06 21:28:29

模拟器中没有加速器。

“硬件→摇动手势”是通过直接向活动应用程序发送 UIEvent 来生成的。

虽然摇动手势是使用设备上的加速器实现的,但从概念上讲,它们是两种不同类型的用户输入——手势是一个事件,加速度是连续变化。因此,对于仅使用此类手势(例如,摇动以撤消)但不需要知道确切的加速度矢量的应用程序,存在摇动手势菜单项。

There's no accelerator in the simulator.

The "Hardware → Shake Gesture" is generated by directly sending a UIEvent to the active application.

Although Shake Gesture is implemented using the accelerator on the device, conceptually they are two different kind of user input — the gesture is an event, the acceleration is continuous variation. Thus the Shake Gesture menu item exists for the apps which only use such gesture (e.g. Shake to Undo) but do not need to know the exact acceleration vector.

○愚か者の日 2024-09-06 21:28:29

加速计不适用于 iPhone/iPod 模拟器。 “硬件->摇动手势”均不使用加速度计,也不使用模拟器上 safari 的方向变化。

Accelerometer does not work on iPhone/iPod Simulator. Neither "Hardware->Shake Gesture" use accelerometer nor the orientation change of safari on simulator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文