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

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

      1. <small id='B9XcX'></small><noframes id='B9XcX'>

        <tfoot id='B9XcX'></tfoot>
      2. 带有进度条的 UIWebView

        时间:2023-10-22

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

        <tfoot id='gAvx9'></tfoot>
        <legend id='gAvx9'><style id='gAvx9'><dir id='gAvx9'><q id='gAvx9'></q></dir></style></legend>
            <tbody id='gAvx9'></tbody>

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

                • <i id='gAvx9'><tr id='gAvx9'><dt id='gAvx9'><q id='gAvx9'><span id='gAvx9'><b id='gAvx9'><form id='gAvx9'><ins id='gAvx9'></ins><ul id='gAvx9'></ul><sub id='gAvx9'></sub></form><legend id='gAvx9'></legend><bdo id='gAvx9'><pre id='gAvx9'><center id='gAvx9'></center></pre></bdo></b><th id='gAvx9'></th></span></q></dt></tr></i><div id='gAvx9'><tfoot id='gAvx9'></tfoot><dl id='gAvx9'><fieldset id='gAvx9'></fieldset></dl></div>
                • 本文介绍了带有进度条的 UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  您好,我是编程新手,我正在尝试在 Xcode 上为 iPhone 制作我的第一个应用程序.我的应用程序包含一个按钮,该按钮在按下时打开 UIWebView 并加载主页.现在我还想像 Safari 一样向 WebView 添加一个进度视图,它指示加载页面的进度.我该怎么做?
                  到目前为止,我用于在 UIWebView 中加载 URL 的代码:

                  Hi I'm new to programming and I'm trying to make my first app for iPhones on Xcode. My app contains of a button which opens a UIWebView when pressed and loads up a homepage. Now I also want to add a Progress View to the WebView like Safari also uses, which indicates the progress of loading the page. How can I do that?
                  My code so far for loading the URL in the UIWebView:

                  .h

                  IBOutlet UIWebView *webView;
                  

                  .m

                  - (void)viewDidLoad
                  {
                  [webView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:@"http:/www.google.com/"]]];
                  

                  感谢您的帮助!

                  推荐答案

                  要想有一个准确的UIProgressView,你需要有一些任务:

                  To have an accurate UIProgressView, you need to have some task that:

                  • 您可以在信息不完整时从中获取信息
                  • 根据该信息将其完整性"量化为百分比.

                  现在,当您加载 UIWebView 时,这是不可能的.苹果也不这样做.Apple 经常使用伪造的 UIProgressView 来在页面加载时为您提供一些可以查看的内容.Mail 还使用虚假的进度视图.自己去试试吧.这就是 Apple 的虚假进度视图的工作原理:

                  Now when you are loading your UIWebView, thats not possible. And Apple doesn't do it either. Apple often uses fake UIProgressViews to give you something to look at while the page is loading. Mail also uses fake progress views. Go try it out for yourself. This is how Apple's fake progress views work:

                  • 进度视图开始以缓慢、恒定的速度移动
                  • 如果任务在进度条完成之前完成,它会突然拉到 100%,然后消失
                  • 如果任务需要很长时间,进度视图将在 95% 处停止并一直停留到任务完成.

                  要实现这一点,您必须手动为 progressView 设置动画.您可以将其子类化,但这对您来说可能有点先进.最简单的方法是:

                  To achieve this, you will have to animate the progressView manually. You could subclass it but that would probably be a bit advanced for you. The simplest way would be this:

                  在 myViewController.h 中

                  In myViewController.h

                  @interface myViewController : UIViewController {
                       BOOL theBool;
                       //IBOutlet means you can place the progressView in Interface Builder and connect it to your code
                       IBOutlet UIProgressView* myProgressView;
                       NSTimer *myTimer;
                  }
                  @end
                  

                  在 myViewController.m 中

                  In myViewController.m

                  #import "myViewController.h"
                  @implementation myViewController
                  - (void)webViewDidStartLoad:(UIWebView *)webView{
                       myProgressView.progress = 0;
                       theBool = false;
                       //0.01667 is roughly 1/60, so it will update at 60 FPS
                       myTimer = [NSTimer scheduledTimerWithTimeInterval:0.01667 target:self selector:@selector(timerCallback) userInfo:nil repeats:YES];
                  }
                  - (void)webViewDidFinishLoad:(UIWebView *)webView{
                       theBool = true;
                  }
                  -(void)timerCallback {
                      if (theBool) {
                           if (myProgressView.progress >= 1) {
                                myProgressView.hidden = true;
                                [myTimer invalidate];
                           }
                           else {
                                myProgressView.progress += 0.1;
                           }
                      }
                      else {
                           myProgressView.progress += 0.05;
                           if (myProgressView.progress >= 0.95) {
                                myProgressView.progress = 0.95;
                           }
                      }
                  }
                  @end
                  

                  然后,在您的任务完成的地方,设置 theBool = true; 并且进度视图将自行处理.更改 if 语句中的值以控制动画的速度.

                  Then, where your task gets completed, set theBool = true; and the progress view will take care of itself. Change the values in the if statement thing to control the speed of the animation.

                  这篇关于带有进度条的 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何更改 WKWebView 或 UIWebView 默认字体 下一篇:如何在自定义控件中添加放大镜?

                  相关文章

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

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

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