先说下当前我为处理动画的思路: (新手上路, 老司机轻喷,如果有更好的实现方法请大神指教 感恩戴德)

#1. 分析动画构成

#2. 如果是位移动画则考虑使用BasicAnimation或者KeyframeAnimation实现, 需要的话再搭配缓动函数

#3. 比较复杂的动画则考虑是否用UIBezierpath一帧帧来画

今天我们模仿做一个场景切换加载等待动画, 比如这样的

我们分析下这张图的构成

#1. 一个灰色的背景

#2. 一个白色的圆环

#3. 一个闭合的圆弧(白色部分)

看起来不是简单的位移动画了, 我们用UIBezierPath加CADisplayLink一帧一帧来画试试看

灰色的背景,

这个比较简单, 我们直接创建一个UIView子类, 背景颜色设置为灰色

白色的圆环,

可以用UIBezierPath直接画一个圆,注意调整线的宽度 So easy

    //添加外圆
UIBezierPath *apath = [UIBezierPath bezierPath];
apath.lineWidth = ;
[apath addArcWithCenter:CGPointMake(, ) radius: startAngle: endAngle: * M_PI clockwise:YES]; [apath stroke];

闭合的圆弧,

一样用UIBezierPath, 先设置圆心 画一个圆弧然后闭合路径, _count是设置的一个变量, 有Controller中的计时器控制以达到动画的效果

//先画内圆

    //设置线条
path.lineWidth = ;
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound; //设置圆心
[path moveToPoint:CGPointMake(_myWidth / , _myHeight / )]; //设置内切圆弧
[path addArcWithCenter:CGPointMake(_myWidth / , _myHeight / ) radius: startAngle: M_PI * / endAngle:M_PI * / + * M_PI / * _count clockwise:YES]; //线路闭合
[path closePath]; [path fill];

要注意调整外圆和内闭合弧的线宽

然后在Controller中创建计时器, 改变_count的值达到动画的效果

上代码:

先创建一个UIView子类,

#import <UIKit/UIKit.h>

@interface MyView : UIView

@property (nonatomic, assign) CGFloat   myWidth;
@property (nonatomic, assign) CGFloat myHeight;
@property (nonatomic, assign) NSInteger count; @end

在drawRect中添加图案

#import "MyView.h"

@implementation MyView

- (id)initWithFrame:(CGRect)frame {

    CGRect myFrame = CGRectMake(frame.origin.x, , frame.size.width, frame.size.height);

    self = [super initWithFrame:myFrame];
if (self) { self.myWidth = frame.size.width;
self.myHeight = frame.size.height; } return self;
} - (void)drawRect:(CGRect)rect {
// Drawing code //设置线条颜色
UIColor *color = [UIColor whiteColor];
[color set]; //画内圆
UIBezierPath *path = [UIBezierPath bezierPath]; //设置线条
path.lineWidth = ;
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound; //设置圆心
[path moveToPoint:CGPointMake(_myWidth / , _myHeight / )]; //设置内切圆弧
[path addArcWithCenter:CGPointMake(_myWidth / , _myHeight / )
radius: startAngle: M_PI * /
endAngle:M_PI * / + * M_PI / * _count
clockwise:YES]; //线路闭合
[path closePath]; [path fill]; //添加外圆
UIBezierPath *apath = [UIBezierPath bezierPath];
apath.lineWidth = ;
[apath addArcWithCenter:CGPointMake(, )
radius:
startAngle:
endAngle: * M_PI
clockwise:YES]; [apath stroke]; } @end

在Controller中调用

#import "ViewController.h"
#import "MyView.h" @interface ViewController () @property (nonatomic, strong) MyView *myView;
@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic, assign) NSInteger count; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //创建计时器
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(countOn)];
_displayLink.paused = YES; [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; //创建自定义View实例
_myView = [[MyView alloc] initWithFrame:CGRectMake(, , , )];
_myView.backgroundColor = [UIColor grayColor];
_myView.count = ;
[self.view addSubview:_myView]; //在这里可以添加额外动画, 设置hud出现的方式
[UIView animateWithDuration:0.5 animations:^{ _myView.frame = CGRectMake(, , , );
_displayLink.paused = NO;
}]; } //计时器事件, 修改动画参数
- (void)countOn { _count++;
_myView.count = _count; if (_count > ) { [_displayLink invalidate];
[_myView removeFromSuperview];
} //重绘
[_myView setNeedsDisplay];
}

创建简单动画(一) --- 常规hud的更多相关文章

  1. Web Service 的创建简单编码、发布和部署

    最近,老大准备将已有的C/S架构项目中的通信部分做成通用,需要将其支持WebService为以后项目向着B/S架构升级做好铺垫,为此身为屌丝的我去各种百度WebService是个什么卵玩意,然后逐渐搭 ...

  2. UIView简单动画

    UIView动态实现的效果有以下几种: 1.动态改变frame 2.动态改变color 3.动态改变alpha 4.动态改变bounds 首先,我们先看几种BasicView动画 #pragma ma ...

  3. JQuery(二)——简单动画效果

    上一篇博客总结了JQuery的一些基本知识,这篇博客重点从JQuery能够制造各种各样的网页效果方面来进行总结.总结一些常见的常用的基本效果的必备方法.从隐藏显示,淡入淡出,滑动,动画等几个方面来简单 ...

  4. UI设计篇·入门篇·简单动画的实现,透明动画/旋转动画/移动动画/缩放动画,混合动画效果的实现,为动画设置监听事件,自定义动画的方法

    基本的动画构成共有四种:透明动画/旋转动画/移动动画/缩放动画. 配置动画的方式有两种,一种是直接使用代码来配置动画效果,另一种是使用xml文档配置动画效果 相比而言,用xml文档写出来的动画效果,写 ...

  5. Android成长之路-实现简单动画

    实现简单动画: 在drawable目录中放入图片, 并且创建xml文件 frame.xml 存入图片,如下: <pre class="html" name="cod ...

  6. iOS CAReplicatorLayer 简单动画

    代码地址如下:http://www.demodashi.com/demo/11601.html 写在最前面,最近在看学习的时候,偶然间发现一个没有用过的Layer,于是抽空研究了下,本来应该能提前记录 ...

  7. [.NET] WebApi 生成帮助文档及顺便自动创建简单的测试工具

    ==========最终的效果图========== ==========下面开始干活:生成帮助文档========== 一.创建 WebApi 项目 二.找到 HelpPageConfig.cs 并 ...

  8. Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机

    <Windows Azure Platform 系列文章目录> 本文介绍的是国外的Azure Global.如果是国内由世纪互联运维的Azure China,请参考这篇文档: Azure ...

  9. myeclipse(2015)中创建简单的Maven项目的步骤(用于生成可执行jar文件)------》myeclipse2015

    利用MyEclipse的引导,可以很方便的创建简单的.用于生成可执行jar文件的Maven项目: 1.New -> Project... 选择 Maven Project, 点击Next > ...

随机推荐

  1. 在.Net MVC中自定义ValidationAttribute标签对Model中的属性做验证

    写一个继承与ValidationAttribute类的自定义的验证方法 MVC中传递数据时,大多数都会用Model承载数据,并且在传到控制器后,对Model进行一系列的验证. 我平时经常使用的判断方法 ...

  2. MSMQ小Demo

    Demo基于http://www.cnblogs.com/zhili/p/MSMQ.html Server代码: using System.Messaging; using System.Text; ...

  3. 判断字符串是否为UTF8编码

    UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码.由Ken Thompson于1992年创建.现在已经标准化为RFC 36 ...

  4. Spring Aspect 用法略讲

    『配置Aspect』 若要启用AspectJ风格的注解则必须额外的导入AspectJ的jar包,此外还需要在spring的配置文件中进行配置,配置方式有两种; 一.在配置文件的Schema中进行配置 ...

  5. WebService第二天

    WebService第二天 课程安排:(CXF+HESSIAN) 框架CXF概述(是什么,SOA概述,下载安装) CXF快速入门(服务端.客户端开发,日志拦截器,SOAP版本相互调用的) CXF与sp ...

  6. Linux权限解释

    从左至右,第一位数字代表文件所有者的权限,第二位数字代表同组用户的权限,第三位数字代表其他用户的权限. 而具体的权限是由数字来表示的,读取的权限等于4,用r表示:写入的权限等于2,用w表示:执行的权限 ...

  7. mongodb集群+分片部署(二)

    机器:10.165.38.68    10.165.38.72 部署包:mongodb-linux-x86_64-rhel55-3.0.2.tgz(百度云盘下载地址:http://pan.baidu. ...

  8. C#获取网页内容 (WebClient、WebBrowser和HttpWebRequest/HttpWebResponse)

    获取网页数据有很多种方式.在这里主要讲述通过WebClient.WebBrowser和HttpWebRequest/HttpWebResponse三种方式获取网页内容. 这里获取的是包括网页的所有信息 ...

  9. 2016 C++及系统软件技术大会亮点

    2016 C++及系统软件技术大会将于201610月28日-29日在上海举办!此次2016 C++及系统软件技术大会秉承"全球专家. 连接智慧"的理念!大会特邀C++之父Bjarn ...

  10. magento寄存器的使用

    1.Mage::register('validation_image_name', $validationImageName);//这个是把变量$validationImageName存储在valid ...