• <bdo id='oMpS1'></bdo><ul id='oMpS1'></ul>

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

      <legend id='oMpS1'><style id='oMpS1'><dir id='oMpS1'><q id='oMpS1'></q></dir></style></legend>
    1. <tfoot id='oMpS1'></tfoot>
      <i id='oMpS1'><tr id='oMpS1'><dt id='oMpS1'><q id='oMpS1'><span id='oMpS1'><b id='oMpS1'><form id='oMpS1'><ins id='oMpS1'></ins><ul id='oMpS1'></ul><sub id='oMpS1'></sub></form><legend id='oMpS1'></legend><bdo id='oMpS1'><pre id='oMpS1'><center id='oMpS1'></center></pre></bdo></b><th id='oMpS1'></th></span></q></dt></tr></i><div id='oMpS1'><tfoot id='oMpS1'></tfoot><dl id='oMpS1'><fieldset id='oMpS1'></fieldset></dl></div>
      1. 为什么在 UIWebView iPhone 中滚动时计时器停止?

        时间:2023-10-22
          <tbody id='dJLVv'></tbody>
        <i id='dJLVv'><tr id='dJLVv'><dt id='dJLVv'><q id='dJLVv'><span id='dJLVv'><b id='dJLVv'><form id='dJLVv'><ins id='dJLVv'></ins><ul id='dJLVv'></ul><sub id='dJLVv'></sub></form><legend id='dJLVv'></legend><bdo id='dJLVv'><pre id='dJLVv'><center id='dJLVv'></center></pre></bdo></b><th id='dJLVv'></th></span></q></dt></tr></i><div id='dJLVv'><tfoot id='dJLVv'></tfoot><dl id='dJLVv'><fieldset id='dJLVv'></fieldset></dl></div>

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

                1. <legend id='dJLVv'><style id='dJLVv'><dir id='dJLVv'><q id='dJLVv'></q></dir></style></legend>
                2. 本文介绍了为什么在 UIWebView iPhone 中滚动时计时器停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能重复:
                  UIScrollView 暂停 NSTimer 直到滚动完成

                  我很难弄清楚为什么 NSTimer 在我滚动 UIWebView 时立即停止.请看下面的代码(我知道这不是一个家庭作业网站,但老实说我被卡住了):

                  I am having a bit of trouble figuring out why the NSTimer stops as soon as I scroll in the UIWebView. Please take a look at the following code (I know this isn't a homework site, but I honestly am stuck):

                  - (void)viewDidLoad {
                      [super viewDidLoad];
                      NSString *address = @"http://en.m.wikipedia.org/wiki/";
                      NSURL *url = [NSURL URLWithString:address];
                      NSURLRequest *request = [NSURLRequest requestWithURL:url];
                      [wiki loadRequest:request];
                      time = 0;
                      countValue = 0;
                      timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(updateTimer) userInfo: nil repeats: YES];
                      timeRand = 0;
                      countValueRand = 1;
                      randomTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(updateRandomTimer) userInfo: nil repeats: YES];
                      [self generateWordsArray];
                  }
                  

                  推荐答案

                  您必须将计时器添加到另一个 RunLoopMode.默认情况下,将计时器添加到 NSDefaultRunLoopMode.这意味着计时器仅在应用的运行循环处于 NSDefaultRunLoopMode 时才会执行.

                  You have to add the timer to another RunLoopMode. Per default a timer is added to the NSDefaultRunLoopMode. That means that the timer is only executing when the app’s run loop is in NSDefaultRunLoopMode.

                  现在,当用户触摸屏幕(例如滚动 UIScrollView)时,运行循环的模式将切换到 NSEventTrackingRunLoopMode.现在,运行循环不再处于 NSDefaultRunMode 中,计时器将不会执行.这样做的丑陋效果是,每当用户触摸屏幕时,计时器就会被阻止.当用户滚动时,这可能是一个很长的时间,因为计时器被阻塞,直到滚动完全停止.而当用户继续滚动时,定时器又被阻塞了.

                  Now, when a user touches the screen (e.g. to scroll a UIScrollView) the run loop’s mode will be switched to NSEventTrackingRunLoopMode. And now, that the run loop is not in NSDefaultRunMode anymore, the timer will not execute. The ugly effect of that is, that timer is blocked whenever the user touches the screen. And that can be a looong time when the user is scrolling, because the timer is blocked until the scrolling completely stops. And when the user continues to scroll, the timer is blocked again.

                  幸运的是,这个问题的解决方案非常简单:您可以将计时器添加到另一个 NSRunLoopMode.当将计时器添加到 NSRunLoopCommonModes 时,它将在所有运行循环模式下执行(准确地说,这些模式已被声明为通用"模式集的成员).这意味着计时器不仅在 NSDefaultRunLoopMode 下工作,而且在 NSEventTrackingRunLoopMode 下工作(当用户触摸屏幕时).

                  Fortunately the solution to this problem is quite simple: You can add your timer to another NSRunLoopMode. When add the timer to NSRunLoopCommonModes it will execute in all run loop modes (that have been declared as a member of the set of "common" modes, to be precise). That means that the timer is not only working in NSDefaultRunLoopMode but also in NSEventTrackingRunLoopMode (when the user touches the screen).

                  所以在你初始化你的定时器之后,将它添加到 NSRunLoopCommonModes:

                  So after you initialize your timer, add it to NSRunLoopCommonModes:

                  [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
                  

                  这篇关于为什么在 UIWebView iPhone 中滚动时计时器停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将方向更改为横向后,uiwebview 未调整大小 下一篇:UIWebView 中的 iPhone 键盘不会消失

                  相关文章

                3. <tfoot id='tyqBB'></tfoot>

                  1. <legend id='tyqBB'><style id='tyqBB'><dir id='tyqBB'><q id='tyqBB'></q></dir></style></legend>

                  2. <small id='tyqBB'></small><noframes id='tyqBB'>

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