沿着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路径做动画的更多相关文章

  1. 让CALayer的shadowPath跟随bounds一起做动画改变-b

    在iOS开发中,我们经常需要给视图添加阴影效果,最简单的方法就是通过设置CALayer的shadowColor.shadowOpacity.shadowOffset和shadowRadius这几个属性 ...

  2. svg路径蒙版动画

    svg路径蒙版动画,是比较实用的一种动画效果,能够绘制如下图所示的动画. 接下来细说这样的动画是如何做成的: 1.准备工作 2.SVG路径动画 3.SVG路径蒙版动画 4.复杂图形的编辑技巧 1.准备 ...

  3. Linux系统下修改环境变量PATH路径的三种方法

    这里介绍Linux的知识,比如把/etc/apache/bin目录添加到PATH中有三种方法,看完之后你将学会Linux系统下如何修改环境变量PATH路径,需要的朋友可以参考下 电脑中必不可少的就是操 ...

  4. 如何修改Window系统下PATH路径以及win8下masm32V11

    如何修改Window系统下PATH路径   //其实这个都是临时性的, 退出dos窗口就没有用了,只是做个笔记罢了   C:\Users\Administrator>    set path=E ...

  5. [UWP]用Shape做动画

    相对于WPF/Silverlight,UWP的动画系统可以说有大幅提高,不过本文无意深入讨论这些动画API,本文将介绍使用Shape做一些进度.等待方面的动画,除此之外也会介绍一些相关技巧. 1. 使 ...

  6. [UWP]用Shape做动画(2):使用与扩展PointAnimation

    上一篇几乎都在说DoubleAnimation的应用,这篇说说PointAnimation. 1. 使用PointAnimation 使用PointAnimation可以让Shape变形,但实际上没看 ...

  7. css3 svg路径蒙版动画

    css3 svg路径蒙版动画 具体看https://www.cnblogs.com/oubenruing/p/9568954.html 还有个更好控制的写法<pre><!DOCTYP ...

  8. canvas做动画

    一.绘制图片 ①加载图片 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  9. 使用snapjs实现svg路径描边动画

    一,snap.svg插件在近几天,突然接到一个需求,内容是要在网页上写一个路径的动画,还需要可以随意控制动画的速度,开始于结束,本来是一个图片可以解决的问题,结果就这样变难了呀,在网上查一会之后,突然 ...

随机推荐

  1. Little-endian和Big-endian

    谈到字节序的问题,必然牵涉到两大CPU派系.那就是Motorola的PowerPC系列CPU和Intel的x86系列CPU.PowerPC系列采用big endian方式存储数据,而x86系列则采用l ...

  2. C#获取特定进程CPU和内存使用率

    首先是获取特定进程对象,可以使用Process.GetProcesses()方法来获取系统中运行的所有进程,或者使用Process.GetCurrentProcess()方法来获取当前程序所对应的进程 ...

  3. js replace,正则截取字符串内容

    1.js replace替换,使用 http://www.jb51.net/article/43949.htm 顺便记录一下 e.g. js获取sql中的可替换参数$id,$name."SE ...

  4. zabbix3.4+grafana5.0.1数据可视化

    转自:https://blog.csdn.net/xiaoying5191/article/details/79530280

  5. 如何对手机使用adb

    因为要配合前端做测试,所以我需要在本机中安装adb驱动,以便可以连接手机进行各种操作. 好吧...装adb驱动这块当时我没有把流程给做记录...郁闷,下次再安装的时候再谷歌吧. 使用的简单脚本就是 有 ...

  6. HDU 5628 Clarke and math dp+数学

    Clarke and math 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5628 Description Clarke is a patient ...

  7. HTML5开启浏览器桌面通知 Web Notification

    说明: 1.Chrome要求必须https才可以开启浏览器通知 2.显示图片在本服务器,不支持跨越 3.自定义声音Chrome不播放,Firefox正常播放 代码如下: <!-- /** * @ ...

  8. BZOJ.4032.[HEOI2015]最短不公共子串(DP 后缀自动机)

    题目链接 1.求A的最短子串,它不是B的子串. 子串是连续的,对B建SAM,枚举起点,在SAM上找到第一个无法匹配点即可.O(n)用SAM能做吗..开始想错了. 2.求A的最短子串,它不是B的子序列. ...

  9. 分位函数(四分位数)概念与pandas中的quantile函数

    p分位函数(四分位数)概念与pandas中的quantile函数 函数原型 DataFrame.quantile(q=0.5, axis=0, numeric_only=True, interpola ...

  10. 吴恩达-coursera-机器学习-week5

    九.神经网络的学习(Neural Networks: Learning) 9.1 代价函数 9.2 反向传播算法 9.3 反向传播算法的直观理解 9.4 实现注意:展开参数 9.5 梯度检验 9.6 ...