• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
手写的从前
博客园    首页    新随笔    联系   管理    订阅  订阅

Windows Phone 十九、罗盘

磁力计概述

拥有磁力计硬件支持的设备可以根据磁力计来确定相对于北极的角度

磁力计的访问 API 定义在 Compass 类中

调用方式和加速计类似

1     <Grid Background="White">
2         <Image Source="compass.png" RenderTransformOrigin="0.5,0.5">
3             <Image.RenderTransform>
4                 <CompositeTransform x:Name="rotate" Rotation="1"/>
5             </Image.RenderTransform>
6         </Image>
7     </Grid>
 1         protected override void OnNavigatedTo(NavigationEventArgs e)
 2         {
 3             Compass c = Compass.GetDefault();
 4             if (c == null)
 5             {
 6                 // 不支持罗盘
 7                 return;
 8             }
 9             c.ReadingChanged += async (p1, p2) =>
10             {
11                 // 修改图片的旋转角度;
12                 System.Diagnostics.Debug.WriteLine(p2.Reading.HeadingTrueNorth.Value);
13                 await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
14                 {
15                     rotate.Rotation = -p2.Reading.HeadingTrueNorth.Value;
16                 });
17             };
18             c.ReportInterval = c.MinimumReportInterval * 10;
19         }

 

posted @ 2015-06-26 01:34  手写从前  阅读(137)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3