沿着path路径做动画
沿着path路径做动画
路径
效果
源码
//
// ViewController.m
// PathAnimation
//
// Created by YouXianMing on 16/1/26.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "ViewController.h" @interface ViewController () @property (nonatomic) CGPoint startPoint;
@property (nonatomic) CGPoint endPoint; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 起始点 结束点
self.startPoint = CGPointMake(, );
self.endPoint = CGPointMake(, ); // 初始化view
UIButton *redButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
redButton.center = self.startPoint;
redButton.backgroundColor = [UIColor redColor];
[redButton addTarget:self action:@selector(buttonEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:redButton]; // CAKeyframeAnimation
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = [self path].CGPath;
animation.duration = .f;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; redButton.center = self.endPoint;
[redButton.layer addAnimation:animation forKey:nil];
} - (UIBezierPath *)path { UIBezierPath* bezierPath = [UIBezierPath bezierPath]; [bezierPath moveToPoint: self.startPoint];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: self.endPoint]; return bezierPath;
} - (void)buttonEvent { // todo
} @end
细节
效果
源码
//
// ViewController.m
// PathAnimation
//
// Created by YouXianMing on 16/1/26.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "ViewController.h" @interface ViewController () @property (nonatomic) CGPoint startPoint;
@property (nonatomic) CGPoint endPoint; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 起始点 结束点
self.startPoint = CGPointMake(, );
self.endPoint = CGPointMake(, ); // 初始化view
UIButton *redButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
redButton.center = self.startPoint;
redButton.backgroundColor = [UIColor redColor];
[redButton addTarget:self action:@selector(buttonEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:redButton]; // CAKeyframeAnimation
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = [self path].CGPath;
animation.duration = .f;
animation.autoreverses = true;
animation.repeatCount = CGFLOAT_MAX;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [redButton.layer addAnimation:animation forKey:nil];
} - (UIBezierPath *)path { UIBezierPath* bezierPath = [UIBezierPath bezierPath]; [bezierPath moveToPoint: self.startPoint];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: CGPointMake(, )];
[bezierPath addLineToPoint: self.endPoint]; return bezierPath;
} - (void)buttonEvent { // todo
} @end
细节
沿着path路径做动画的更多相关文章
- 让CALayer的shadowPath跟随bounds一起做动画改变-b
在iOS开发中,我们经常需要给视图添加阴影效果,最简单的方法就是通过设置CALayer的shadowColor.shadowOpacity.shadowOffset和shadowRadius这几个属性 ...
- svg路径蒙版动画
svg路径蒙版动画,是比较实用的一种动画效果,能够绘制如下图所示的动画. 接下来细说这样的动画是如何做成的: 1.准备工作 2.SVG路径动画 3.SVG路径蒙版动画 4.复杂图形的编辑技巧 1.准备 ...
- Linux系统下修改环境变量PATH路径的三种方法
这里介绍Linux的知识,比如把/etc/apache/bin目录添加到PATH中有三种方法,看完之后你将学会Linux系统下如何修改环境变量PATH路径,需要的朋友可以参考下 电脑中必不可少的就是操 ...
- 如何修改Window系统下PATH路径以及win8下masm32V11
如何修改Window系统下PATH路径 //其实这个都是临时性的, 退出dos窗口就没有用了,只是做个笔记罢了 C:\Users\Administrator> set path=E ...
- [UWP]用Shape做动画
相对于WPF/Silverlight,UWP的动画系统可以说有大幅提高,不过本文无意深入讨论这些动画API,本文将介绍使用Shape做一些进度.等待方面的动画,除此之外也会介绍一些相关技巧. 1. 使 ...
- [UWP]用Shape做动画(2):使用与扩展PointAnimation
上一篇几乎都在说DoubleAnimation的应用,这篇说说PointAnimation. 1. 使用PointAnimation 使用PointAnimation可以让Shape变形,但实际上没看 ...
- css3 svg路径蒙版动画
css3 svg路径蒙版动画 具体看https://www.cnblogs.com/oubenruing/p/9568954.html 还有个更好控制的写法<pre><!DOCTYP ...
- canvas做动画
一.绘制图片 ①加载图片 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- 使用snapjs实现svg路径描边动画
一,snap.svg插件在近几天,突然接到一个需求,内容是要在网页上写一个路径的动画,还需要可以随意控制动画的速度,开始于结束,本来是一个图片可以解决的问题,结果就这样变难了呀,在网上查一会之后,突然 ...
随机推荐
- 【linux】grep的使用
最近发现了grep一个超级好用的指令 1. 在当前目录及其子目录中查找所有包含字符串abc的文件及位置 grep -rn "abc" * 2. 查找不包含"abc&quo ...
- 【转】卖萌的大牛你桑不起啊 ——记CVPR2011一篇极品文章
来源:http://blog.renren.com/share/228707015/7197269922 作者 : 庞宇 CVPR2011正在如火如荼的进行中,在网上能看到的部分文章中,我终于找到一篇 ...
- .NetCore 扩展封装 Expression<Func<T, bool>> 查询条件遇到的问题
前面的文章封装了查询条件 自己去组装条件,但是对 And Or 这种组合支持很差,但是也不是不能支持,只是要写更多的代码看起来很臃肿 根据 Where(Expression<Func< ...
- ddmlib问题总结——同步获取设备信息
通过IDevice.getProperty(String name)得到响应的设备属性.在实际的使用过程中发现,我的manufacturer总是获取不到,为null(获取代码如下),而剩下的属性都可以 ...
- AC自动机学习笔记-1(怎么造一台AC自动机?)
月更博主又来送温暖啦QwQ 今天我们学习的算法是AC自动机.AC自动机是解决字符串多模匹配问题的利器,而且代码也十分好打=w= 在这一篇博客里,我将讲解AC自动机是什么,以及怎么构建一个最朴素的AC自 ...
- linux通过wget直接下载jdk
下载语句: tar包下载 wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-se ...
- MATLAB检查指定路径中的子文件夹中的文件名中是否带有空格
测试文件夹为: clear;close all;clc; %% %程序实现的功能 %检查指定路径中的子文件夹中的文件名中是否带有空格,并去掉文件名中的空格 %% %程序中用到的之前不清楚的函数如下 % ...
- 常见的网络攻击(XSS,SQL注入,CSRF)
一.XSS 二.SQL注入 三.CSRF
- HTTP协议-MIME类型
每一个 URL 都代表着一个资源对象,而当我们请求一个网页的时候,看似只请求了一个 URI(统一资源标识符),实际上这个网页可能包含多个 URI,例如图片资源的 URI 和视频资源的 URI 等.此时 ...
- Django的URL别名
项目的urls.py配置文件 from message.views import getform urlpatterns = [ url(r'^admin/', admin.s ...