【转】在webview加加载数据时添加一个Loading...动画的两种方法

【转】在webview加加载数据时添加一个Loading...动画的两种方法

 

大家使用iPhone/iPod浏览网页时,一定见过浏览器加载网页时,总会出现一个Loading动画,其实这是实现起来是非常简单的。下面就是两种不同的实现方法:


第一种方法:

  1. //创建UIWebView  
  2. WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)];
  3. [WebView setUserInteractionEnabled:NO];
  4. [WebView setBackgroundColor:[UIColor clearColor]];  
  5. [WebView setDelegate:self];  
  6. [WebView setOpaque:NO];//使网页透明  

  7. NSString *path = @"http://www.baidu.com";  
  8. NSURL *url = [NSURL URLWithString:path];  
  9. [WebView loadRequest:[NSURLRequest requestWithURL:url]];

  10. //创建UIActivityIndicatorView背底半透明View  
  11. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];  
  12. [view setTag:103];
  13. [view setBackgroundColor:[UIColor blackColor]];
  14. [view setAlpha:0.8];
  15. [self.view addSubview:view];  

  16. activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
  17. [activityIndicator setCenter:view.center];
  18. [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];  
  19. [view addSubview:activityIndicator];  
  20. [self.view addSubview:WebView];  
  21. [view release];
  22. [WebView release];  

  23. //以下两个方法是UIWebView的delegate methods
  24. //开始加载数据
  25. - (void)webViewDidStartLoad:(UIWebView *)webView {
  26.       [activityIndicator startAnimating];  
  27. }
  28. //数据加载完  
  29. - (void)webViewDidFinishLoad:(UIWebView *)webView {  
  30.      [activityIndicator stopAnimating];  
  31.      UIView *view = (UIView *)[self.view viewWithTag:103];  
  32.      [view removeFromSuperview];
  33. }



第二种方法:在UIAlertView上添加一个UIActivityIndicatorView
  1. //加载网页动画
  2. - (void)webViewDidStartLoad:(UIWebView *)webView{
  3.     if (myAlert==nil){
  4.        myAlert = [[UIAlertView alloc] initWithTitle:nil
  5.                                                               message: @"正在加载数据,请稍候..."
  6.                                                                 delegate: self  
  7.                                                  cancelButtonTitle: nil f
  8.                                                  otherButtonTitles: nil];
  9.      UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  10.      activityView.frame = CGRectMake(120.f, 48.0f, 37.0f, 37.0f);  
  11.      [myAlert addSubview:activityView];
  12.      [activityView startAnimating];
  13.      [myAlert show];
  14. }
  15. }
  16. - (void)webViewDidFinishLoad:(UIWebView *)webView{  
  17.       [myAlert dismissWithClickedButtonIndex:0 animated:YES];
  18. }


安卓-Loading加载中动画 自定义安卓加载中动画,两种方式,随意变化。 立即下载

相关推荐

网页加载动画效果(Loading)

50多少个 网页加载动画效果(Loading效果),加载中,SVG,加载动画

android webview加载动画,WebView加载网页(一)

WebView加载网页一、新建一个android项目新建android项目,应用默认配置,其他地方不做修改。新建一个activity,项目目录结构为:二、修改mainactivitypackage cn.qiu.webview2;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import ...

weixin_29463881的博客 1076

android 加载动画

一个漂亮的 android 加载动画,android 5.0加载动画,可用于低版本

WebView自定义进度条、加载动画,拿走直接用~

年前有个小需求,要对有些域名的H5进行加载流程优化,通过展示H5加载动画来安抚用户焦躁的心情,以提高用户体验。虽然不能理解加个动画咋就优化了用户体验,但需求还是得做的。想着这是个基础的小功能,独立性比较好,遂记录下来,以资来者。

kiba_zwei的博客 2770

【Android】Android开发之常用的loading等待效果实现,仿微博等待动画。两种实现方式详解

博文介绍:http://blog.csdn.net/qq_21376985/article/details/52847317 【Android】Android开发之常用的loading等待效果实现,仿微博等待动画。两种实现方式详解

Android 帧动画实现自定义loading加载框

Android 帧动画实现自定义loading加载框

网页加载时的Loading(七种)

方法一:                  size=2>正在加载:     behavior="slide">███████████████████████████████████████████████████████████████████████████████      var myTime=0  function count

得峰的专栏 [网络收藏] 1888

【STM32G474实战】RS485通信的DMA优化策略与性能对比

本文深入探讨了在STM32G474微控制器上优化RS485通信的DMA策略。通过对比轮询、中断和DMA三种数据传输方式的代码实现与性能,揭示了DMA在解放CPU、降低占用率方面的巨大优势。文章提供了详细的DMA配置指南、高级应用技巧(如结合空闲中断)以及一个高可靠通信框架的实战思路,旨在帮助开发者构建高效、实时的工业控制系统。

weixin_29268331的博客 303

JavaFx控件WebView基础使用

Fxml文件 <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.layout.BorderPane?> <?import javafx.scene.web.WebView?> <BorderPane fx:id="borderPane" xmlns:fx="http://java...

aliaichidantong的博客 3803

链路聚合Eth-trunk以及华为交换机配置实例

链路聚合简介 以太网链路聚合Eth-Trunk简称链路聚合,它通过将多条以太网物理链路捆绑在一起成为一条逻辑链路,从而实现增加链路带宽的目的。同时,这些捆绑在一起的链路通过相互间的动态备份,可以有效地提高链路的可靠性。 目的: 随着网络规模不断扩大,用户对骨干链路的带宽和可靠性提出越来越高的要求。在传统技术中,常用更换高速率的接口板或更换支持高速率接口板的设备的方式来增加带宽,但这种方案需要付出高额的费用,而且不够灵活。 采用链路聚合技术可以在不进行硬件升级的条件下,通过将多个物理接口捆绑为一个逻辑接口

ChaseAug的博客 2万+

用Python实现四叉树(quad tree)

import numpy as np #正方形类 class square: #lx、ly为左上角坐标(x对应行号,y对应列号),rx、ry为右下角坐标 def __init__(self,lx,ly,rx,ry): self.lx=lx self.ly=ly self.rx=rx self.ry=ry #检查该矩阵中是否满足条件 #参数:原矩阵,阈值 #返回值:布尔类型 def check(s

weixin_44164489的博客 5868

android webview loading,Android WebView+ProgressBar Loading...

import android.content.Context;import android.os.Build;import android.text.TextUtils;import android.util.AttributeSet;import android.view.View;import android.webkit.WebChromeClient;import android.webk...

weixin_39524247的博客 246

飞思卡尔16位单片机(二)——CodeWarrior开发环境搭建及新建、调试工程

一、安装CodeWarrior 飞思卡尔16位单片机的开发环境为CodeWarrior5.1,这个软件安装比较简单,软件的安装文件可以从相应的网站上下载。安装CodeWarrior所需要的电脑的硬件资源也比较宽泛,目前一般的电脑都可以满足这个要求,可以支持win10、win7等操作系统。安装过程按照按照软件的提示一步步操作即可。 二、安装USBDM驱动 USBDM是...

bigmarshal的博客 1万+

UIWebView加载Loading...两种方法

from: http://blog.csdn.net/sjzsp/article/details/6541538 第一种方法:使用UIView and UIActivityIndicatorView  //创建UIWebView  WebView = [ [ UIWebView alloc ] initWithFrame : CGRectMake( 0 , 4

wangyx810328的专栏 561

200SMART PLC时间不准?手把手教你用MCGS触摸屏实现自动校时(附完整代码)

本文针对西门子200SMART PLC时钟不准的常见问题,提供了一套基于MCGS触摸屏的自动校时解决方案。文章详细阐述了时钟偏差的根源、时间同步方案的技术选型,并手把手指导如何配置MCGS与PLC的通信,以及编写完整的PLC时间读取、转换与设置代码,最终实现稳定可靠的自动时间同步功能。

jupyter5notebook的博客 456

QT6与QT5安装全攻略:从下载到环境配置一站式指南

本文提供了一份详尽的QT6与QT5安装教程,涵盖从版本选择、在线安装器使用到环境变量配置的全过程。针对新手常见痛点,重点对比了QT6与QT5的安装差异,并给出了MinGW与MSVC编译器的选择建议,旨在帮助开发者快速搭建稳定可用的QT开发环境,避免常见错误。

weixin_29216353的博客 310

Android在WebView加载数据时展示loading的Dialog

Android在WebView就在数据时展示loading的Dialog

C_xundaozhe的博客 6335

YOLOv8改进 | 特殊场景检测篇 | 最新的多尺度特征提取DICAM(全网独家首发,增强水下图像的质量)

本文给大家带来的最新改进机制是多尺度特征提取和通道注意力机制DICAM,深度Inception和通道注意力模块(DICAM)主要用于用于增强水下图像的质量、对比度和色偏。所提出的DICAM模型考虑了水下图像的比例退化和不均匀色偏,从而提高图像的质量。通过在两个公开的水下图像增强数据集上的广泛实验,验证了提出的模型在全参考和无参考图像质量评估指标方面。欢迎大家订阅我的专栏一起学习YOLO,购买专栏读者联系读者入群获取进阶项目文件!

Snu77的博客 2216

Android 图片Loading旋转动画效果

在数据请求或者一些加载的页面中,总需要一些过度的动画效果,很多时候我们都可以在图片中间加一个loading的旋转图片,以前也做过,今天做的时候噼里啪啦敲了半天结果运行没效果,所以今天总结下这个啷个做的。eg:animation只是操作View 的位图表示(bitmap representation),而不是真正的改变View的位置,位图就是bitmap,关于bitmap,可以去好好学习一下!例子:我们要加载一个webView,需要在加载前的空白页面中间加一个旋转的loading图片,结束后就消失。

Android 领域开发程序员,希望通过写博客的方式不断的总结提升自己,大家共同进步哦! 4226

黑猫带你学eMMC协议第22篇:emmc可靠写详解(Write Reliability)

1 前言 1.1 声明 本文依据eMMC JEDEC5.1、网络资料及个人工作经验整理而成,如有部分错误请留言。 本文部分内容可能源自网络,侵删。 本文结合eMMC JEDEC5.1协议手册查看效果更佳。 1.2 内容提要 1、什么是可靠性写属性(Write Reliability)? 2、可靠写和普通的写有什么区别? 3、设置可靠写的流程及流程框图。 4、可靠写需要遵循哪些规则? 1.3 参考链接 本文主要参考链接:http://www.up48.com/cn/support/8_37.html 2 什么

黑猫奥利奥的博客 3122

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

IOS系统中网络等待的Loading的实现方法 等待加载

IOS系统中网络等待的Loading的实现方法 等待加载

sammyieveo的专栏 6400

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

android界面加载不出来了,Android webView点击h5中按钮后加载不出来之后的页面(loading状态或者空白页面)解决之法...

之前项目中遇到一个问题,项目中webView加载h5广告,在h5中提交数据时,竟然一直显示loading而不加载提交成功界面,在此记录一下解决之法,分享给遇到同样问题的伙伴们。运维人员提交这个问题后,第一时间考虑的是,测试原始链接在手机浏览器加载中是否正常?ios是否可以?然而,经过简单的运行测试,只有android端会出现此类问题(现象),怎么办呢?Debug看!首先检查一下代码,有没有设置支持...

weixin_29825861的博客 2904

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Vue通过状态为页面切换添加loading、为ajax加载添加loading

以下方法需要引入vuex,另使用了vux的UI框架,ajax添加loading还引入了axios。 一、为页面切换添加loading。   loading.js: import Vue from 'vue' import Vuex from 'vuex' import router from './router' Vue.use(Vuex) const ...

weixin_30402343的博客 449

iOS 加载gif 的两种方式

简单记录一下,排除第三方加载gif 1. 使用webview ,可以根据需要将webview放到一些控件上 如下: -(void)loadGif{ //1.找到gif文件路径 ,SDKPlatform.bundle/loading1 是所在SDKPlatform.bundle中 NSString *dataPath = [[NSBundle mainBundle]...

wang_Bo_JustOne的博客 921
上一篇: iphone认证文件无效解决办法
下一篇: Amazon的aws服务使用笔记
xinlanzero
博客等级 码龄25年 10粉丝 132原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值