CoreMotion框架

发布于 2024-10-21 21:45:54 字数 74 浏览 3 评论 0原文

我最近在做一个指南针,涉及到CoreMotion框架,但是我查了半天没有找到关于这个框架如何实现指南针效果的资料,希望得到大家的帮助。

I recently was doing a compass, to involve CoreMotion framework, but I checked for a long time did not find information on how to implement this framework the effect of the compass, hoping to get everyone's help.

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

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

发布评论

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

评论(2

听风吹 2024-10-28 21:45:54
遇到 2024-10-28 21:45:54

我的“Helloworld”CoreMotion:

1)添加CoreMotion.framework

2)在.h文件中:

#import <CoreMotion/CoreMotion.h>

3)在.m文件中:

CMMotionManager *myMotionManager= [[CMMotionManager alloc] init];
myMotionManager.deviceMotionUpdateInterval = 1/60;
[myMotionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical  toQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
     double x = myMotionManager.deviceMotion.magneticField.field.x;
     double y = myMotionManager.deviceMotion.magneticField.field.y;
     double z = myMotionManager.deviceMotion.magneticField.field.z;
    NSLog(@"Strength of Earth's magnetic field= %8.2f",sqrt(x*x+y*y+z*z));
    myLabel.text = [NSString stringWithFormat:@"%8.2f", sqrt(x*x+y*y+z*z)];
}];

My "Helloworld" CoreMotion:

1) Add CoreMotion.framework

2) in .h file:

#import <CoreMotion/CoreMotion.h>

3) in .m file:

CMMotionManager *myMotionManager= [[CMMotionManager alloc] init];
myMotionManager.deviceMotionUpdateInterval = 1/60;
[myMotionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical  toQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
     double x = myMotionManager.deviceMotion.magneticField.field.x;
     double y = myMotionManager.deviceMotion.magneticField.field.y;
     double z = myMotionManager.deviceMotion.magneticField.field.z;
    NSLog(@"Strength of Earth's magnetic field= %8.2f",sqrt(x*x+y*y+z*z));
    myLabel.text = [NSString stringWithFormat:@"%8.2f", sqrt(x*x+y*y+z*z)];
}];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文