<i id='oHl2o'><tr id='oHl2o'><dt id='oHl2o'><q id='oHl2o'><span id='oHl2o'><b id='oHl2o'><form id='oHl2o'><ins id='oHl2o'></ins><ul id='oHl2o'></ul><sub id='oHl2o'></sub></form><legend id='oHl2o'></legend><bdo id='oHl2o'><pre id='oHl2o'><center id='oHl2o'></center></pre></bdo></b><th id='oHl2o'></th></span></q></dt></tr></i><div id='oHl2o'><tfoot id='oHl2o'></tfoot><dl id='oHl2o'><fieldset id='oHl2o'></fieldset></dl></div>

      <tfoot id='oHl2o'></tfoot>
        <bdo id='oHl2o'></bdo><ul id='oHl2o'></ul>
      1. <small id='oHl2o'></small><noframes id='oHl2o'>

        <legend id='oHl2o'><style id='oHl2o'><dir id='oHl2o'><q id='oHl2o'></q></dir></style></legend>

      2. 如何检测和编程 iPhone 的震动

        how to detect and program around shakes for the iphone(如何检测和编程 iPhone 的震动)

        <small id='Qm3VI'></small><noframes id='Qm3VI'>

            <i id='Qm3VI'><tr id='Qm3VI'><dt id='Qm3VI'><q id='Qm3VI'><span id='Qm3VI'><b id='Qm3VI'><form id='Qm3VI'><ins id='Qm3VI'></ins><ul id='Qm3VI'></ul><sub id='Qm3VI'></sub></form><legend id='Qm3VI'></legend><bdo id='Qm3VI'><pre id='Qm3VI'><center id='Qm3VI'></center></pre></bdo></b><th id='Qm3VI'></th></span></q></dt></tr></i><div id='Qm3VI'><tfoot id='Qm3VI'></tfoot><dl id='Qm3VI'><fieldset id='Qm3VI'></fieldset></dl></div>
              <bdo id='Qm3VI'></bdo><ul id='Qm3VI'></ul>

              <tfoot id='Qm3VI'></tfoot>

              <legend id='Qm3VI'><style id='Qm3VI'><dir id='Qm3VI'><q id='Qm3VI'></q></dir></style></legend>
                    <tbody id='Qm3VI'></tbody>

                  本文介绍了如何检测和编程 iPhone 的震动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在此页面上实现摇动教程",但我认为我遗漏了一些东西.我将他的加速度计功能复制到 myAppViewController.m 文件中,并在其中放置了一些 nslog,以查看当我使用模拟器摇动"功能时它是否进入该功能.调试控制台中没有显示任何内容.

                  I'm trying to implement the shake "tutorial" on this page, but I think I'm missing something. I copied his accelerometer function into myAppViewController.m file and put some nslogs in there to see if it even gets into the function when I use the simulators "shake" function. Nothing shows up in the debug console.

                  http://mithin.in/2009/07/28/detecting-a-shake-using-iphone-sdk

                  谁能解释我可能遗漏了什么?或者指点我一个教程?

                  Can anyone explain what I might be missing? Or point me to a tutorial?

                  我发现了这个,看起来很有希望,但我不知道如何把它放在 UIView 中"如何检测有人摇晃 iPhone?

                  I found this, which looks promising, but I don't know how to "put it in a UIView" How do I detect when someone shakes an iPhone?

                  编辑 - 由于接受了答案的建议,现在这是我的工作代码.

                  EDIT - now here's my working code because of the accepted answer's suggestion.

                  这是我在 3.0 iphone sdk 中检测摇晃手势的代码.

                  Here's my code to detect the shake gesture in 3.0 iphone sdk.

                  -(BOOL)canBecomeFirstResponder {
                      return YES;
                  }
                  
                  -(void)viewDidAppear:(BOOL)animated {
                      [super viewDidAppear:animated];
                      [self becomeFirstResponder];
                  }
                  
                  - (void)viewWillDisappear:(BOOL)animated {
                      [self resignFirstResponder];
                      [super viewWillDisappear:animated];
                  }
                  
                  
                  - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
                      NSLog(@"{motion ended event ");
                  
                      if (motion == UIEventSubtypeMotionShake) {
                          NSLog(@"{shaken state ");
                  
                      }
                      else {
                          NSLog(@"{not shaken state ");       
                      }
                  }
                  

                  推荐答案

                  你应该绝对不要直接用你自己的过滤器来监听 UIAccelerometer 来处理抖动事件.这是一项高功率操作,仅应由需要高加速度计采样率的应用程序使用.使用已添加到 UIEvent 的新运动事件:

                  You should absolutely not be listening to UIAccelerometer directly with your own filtering to handle shake events. That is a high-power operation and should only be used by apps that need a high accelerometer sampling rate. Use the new motion events instead which have been added to UIEvent:

                  http://developer.apple.com/IPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html#//apple_ref/doc/uid/TP40007072-CH9-SW24

                  就像触摸一样,动作事件将被传递给第一响应者,然后如果第一响应者没有响应,则沿着响应者链向上传播.UIEvent 将具有类型 UIEventTypeMotion 和子类型 UIEventSubtypeMotionShake.

                  Just like touches, a motion event will be delivered to the first responder, then travel up the responder chain if the first responder does not respond. The UIEvent will have type UIEventTypeMotion and subtype UIEventSubtypeMotionShake.

                  这篇关于如何检测和编程 iPhone 的震动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iPhone to RS-232 via Bluetooth(iPhone 通过蓝牙转 RS-232)
                  How to change the preferred language of an iPhone app in iOS 4(如何在 iOS 4 中更改 iPhone 应用程序的首选语言)
                  iPhone app localization by releasing separate apps for different markets(通过为不同市场发布单独的应用程序来本地化 iPhone 应用程序)
                  Convert localizable.strings to spreadsheet?(将 localizable.strings 转换为电子表格?)
                  How to determine if locale#39;s date format is Month/Day or Day/Month?(如何确定语言环境的日期格式是月/日还是日/月?)
                  How to quit an iPhone app nicely?(如何很好地退出 iPhone 应用程序?)

                    <tbody id='SIwlg'></tbody>

                  <small id='SIwlg'></small><noframes id='SIwlg'>

                        <i id='SIwlg'><tr id='SIwlg'><dt id='SIwlg'><q id='SIwlg'><span id='SIwlg'><b id='SIwlg'><form id='SIwlg'><ins id='SIwlg'></ins><ul id='SIwlg'></ul><sub id='SIwlg'></sub></form><legend id='SIwlg'></legend><bdo id='SIwlg'><pre id='SIwlg'><center id='SIwlg'></center></pre></bdo></b><th id='SIwlg'></th></span></q></dt></tr></i><div id='SIwlg'><tfoot id='SIwlg'></tfoot><dl id='SIwlg'><fieldset id='SIwlg'></fieldset></dl></div>
                        <tfoot id='SIwlg'></tfoot>

                        <legend id='SIwlg'><style id='SIwlg'><dir id='SIwlg'><q id='SIwlg'></q></dir></style></legend>
                        • <bdo id='SIwlg'></bdo><ul id='SIwlg'></ul>