实现loading动画效果
下面我就来罗列三种实现loading动画效果的方法。
方法一:使用UIImageView自带的方法来实现,这也是我推荐的实现方法。
- NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"],[UIImage imageNamed:@"5.png"], nil nil];
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 200, 80, 30)];
- imageView.animationImages = array; //动画图片数组
- imageView.animationDuration = 2; //执行一次完整动画所需的时长
- // gifImageView.animationRepeatCount = 0; //动画重复次数 0表示无限次,默认为0
- [imageView startAnimating];
- [self.view addSubview:imageView];
方法二:使用UIImageView+NSTimer(定时器)来实现,如果没有猜错的话,第一种方式内部的实现方法也是使用了定时器,只不过我们第二种方法是自己DIY一个属于自己的
控件,自己想要扩展什么功能就扩展什么。
- #import <UIKit/UIKit.h>
- @interface imageAnimation : UIImageView
- @property (strong, nonatomic) NSTimer *animation_timer;
- @property (strong, nonatomic) NSMutableArray *imageArray;
- @property (assign) int currentIndex;
- @property (assign) float interval;
- - (void)startLoading;
- - (void)stopLoading;
- - (void)initLoadingView:(NSMutableArray *)imageArray timeInterval:(float)time;
- @end
- #import "imageAnimation.h"
- @implementation imageAnimation
- @synthesize animation_timer = _animation_timer;
- @synthesize imageArray = _imageArray;
- @synthesize currentIndex = _currentIndex;
- @synthesize interval = _interval;
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- }
- return self;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect
- {
- // Drawing code
- }
- */
- - (void)initLoadingView:(NSMutableArray *)imageArray timeInterval:(float)time{
- self.imageArray = imageArray;
- self.interval = time;
- self.animation_timer = [NSTimer scheduledTimerWithTimeInterval:self.interval target:self selector:@selector(startLoading) userInfo:nil repeats:YES];
- }
- //开始loading
- - (void)startLoading{
- if(!self.imageArray || self.imageArray.count < 1){
- [self.animation_timer invalidate];
- return;
- }
- self.currentIndex = (self.currentIndex +1)%self.imageArray.count;
- self.image = [UIImage imageNamed:[self.imageArray objectAtIndex:self.currentIndex]];
- }
- //结束loading
- -(void)stopLoading{
- [self.animation_timer invalidate];
- }
- @end
方法三:使用UIWebView来加载gif图片,除非你要用到webView,不然就不要使用这种方式来实现
- NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"1" ofType:@"gif"]];
- // view生成
- UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(100, 100, 70, 30)];
- webView.userInteractionEnabled = NO;//用户不可交互
- [webView loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
- [self.view addSubview:webView];
实现loading动画效果的更多相关文章
- ios开发之简单实现loading动画效果
最近有朋友问我类似微信语音播放的喇叭动画和界面图片加载loading界面是怎样实现的,是不是就是一个gif图片呢!我的回答当然是否定了,当然不排除也有人用gif图片啊!下面我就来罗列三种实现loadi ...
- Atitit Loading 动画效果
Atitit Loading 动画效果 使用才场景,加载数据,以及显示警告灯.. 要有手动关闭按钮 <div class="spinner loading_part" sty ...
- [Swift通天遁地]五、高级扩展-(11)图像加载Loading动画效果的自定义和缓存
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- loading动画效果记录
看到好多网页都有一个炫酷的loading动画,以前不知道怎么实现的.今天学习了一下,发现其实也很简单. 首先在学习的时候偶然遇到一个pace.js的库,非常好用.优点是,不需要挂接到任何代码,自动检测 ...
- android动画介绍--Animation 实现loading动画效果
Animation的使用方法并不难.这里简单的介绍一下使用方法. 先看效果图: 效果还是不错的吧. 下面来看看使用方法. 动画效果是通过Animation来实现的,一共有四种,分别为: AlphaAn ...
- CSS3效果:animate实现点点点loading动画效果(二)
box-shadow实现的打点效果 简介 box-shadow理论上可以生成任意的图形效果,当然也就可以实现点点点的loading效果了. 实现原理 html代码,首先需要写如下html代码以及cla ...
- CSS3效果:animate实现点点点loading动画效果(一)
实现如图所示的点点点loading效果: 一:CSS3 animation实现代码 html代码: 提交订单中<span class="ani_dot">...< ...
- css3实现的3中loading动画效果
一.css3中animation动画各种属性详解: animation Value: [<animation-name> || <animation-duration> ...
- javascript 通用loading动画效果
由于项目中多处要给ajax提交的时候增加等待动画效果,所以就写了一个简单的通用js方法: 代码如下: /*ajax提交的延时等待效果*/ var AjaxLoding = new Object(); ...
随机推荐
- MFC 设置控件事件对应的函数
在项目中,右击你想设置的控件,打开属性. 然后找到:控件事件,如果在Visual Studio 2015中操作,显示如图: 然后,以设定单击事件为例: 点击右边的三角,选择 <Edit Code ...
- UE4在C++中使用OnComponentBeginOverlap之类的时间
首先说明一下,官方文档是错的,在4.10版本下,绑定函数在角色类的构造函数中不起作用.2016.2.12 这里角色类为例 首先在头文件中添加: UFUNCTION() void OnOverlapBe ...
- ural 1249. Ancient Necropolis
1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bit ...
- 【SQL】区分新来顾客和再访顾客
-- 赋值 客户来访记录 SELECT m.* FROM (SELECT x.*, CASE WHEN x.ts > (SELECT MIN(a.ts) FROM USER.ps_afterre ...
- Target:IG
https://www.zhihu.com/question/25525630 别人轻轻松松红名,我拼死挣扎才1700+分. 仔细想想,虽然我在这东西上花了太多的精力,可是我根本没有认真学.做题全靠抄 ...
- BZOJ4435 : [Cerc2015]Juice Junctions
最大流=最小割,而因为本题点的度数不超过3,所以最小割不超过3,EK算法的复杂度为$O(n+m)$. 通过分治求出最小割树,设$f[i][j][k]$表示最小割为$i$时,$j$点在第$k$次分治过程 ...
- 【POJ】3974 Palindrome
http://poj.org/problem?id=3974 题意:求s的最长回文串.(|s|<=1000000) #include <cstdio> #include <cs ...
- 'Could not load NIB in bundle: 'NSBundle xxx/storeFlix.app> ' with name 'UIViewController-w6Q-ra-j06' and directory 'StoreFlixIpad.storyboardc
1.此代码是从 git clone xxx 下载的. 2.使用 sourcetree 下载即可解决此问题.
- svn 回滚到上一个版本shell 脚本
#!/bin/sh ############################## # -- # # author jackluo # # Email net.webjoy@gmail.com # ## ...
- java使用poi读取ppt文件和poi读取excel、word示例
java使用poi读取ppt文件和poi读取excel.word示例 http://www.jb51.net/article/48092.htm