沿着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插件在近几天,突然接到一个需求,内容是要在网页上写一个路径的动画,还需要可以随意控制动画的速度,开始于结束,本来是一个图片可以解决的问题,结果就这样变难了呀,在网上查一会之后,突然 ...
随机推荐
- java 把被检查的异常转换为不检查的异常
一.当我们不知道该怎么处理这个异常,但是也不想把它"吞"了,或者打印一些无用的信息,可以使用异常链的思路解决.可以直接报"被检查的异常"包装进RuntimeEx ...
- Java编程的逻辑 (69) - 线程的中断
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...
- Angular 快速学习笔记(1) -- 官方示例要点
创建组件 ng generate component heroes {{ hero.name }} {{}}语法绑定数据 管道pipe 格式化数据 <h2>{{ hero.name | u ...
- js文件的版本控制
使用grunt完成requirejs的合并压缩和js文件的版本控制 最近有一个项目使用了 requirejs 来解决前端的模块化,但是随着页面和模块的越来越多,我发现我快要hold不住这些可爱的j ...
- Codeforces Round #254 (Div. 1) D - DZY Loves Strings
D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...
- ZOJ Monthly, March 2018 题解
[题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...
- Linux下部署tomcat及tomcat war包应用程序
1, 通过winscp将tomcat包(6和7版本都是一样的安装方法)和jdk-6u27-linux-x64.bin安装文件传送到linux 系统/opt里面.(这里没有固定要传送到/opt/hn,可 ...
- 001.Parted工具使用
一 Parted简介 1.1 parted和fdisk 通常使用较多的磁盘管理工具为fdisk,但由于磁盘越来越廉价,且磁盘空间越来越大,而fdisk工具分区存在大小限制,只能划分小于2T的磁盘.因此 ...
- Python - 列表与字符串的互相转换
题目:请将text字符串中的数字取出,并输出成一个新的字符串 text = "aAsmr3 idd4bgs7Dlsf 9eAF" b = list(text) new_list = ...
- MIT-6.828-JOS-lab2:Memory management
MIT-6.828 Lab 2: Memory Management实验报告 tags:mit-6.828 os 概述 本文主要介绍lab2,讲的是操作系统内存管理,从内容上分为三部分: 第一部分讲的 ...