沿着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(0, 150);self.endPoint   = CGPointMake(160, 150);// 初始化viewUIButton *redButton       = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];redButton.center          = self.startPoint;redButton.backgroundColor = [UIColor redColor];[redButton addTarget:self action:@selector(buttonEvent) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:redButton];// CAKeyframeAnimationCAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];animation.path                 = [self path].CGPath;animation.duration             = 2.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(68, 150)];[bezierPath addLineToPoint: CGPointMake(83, 107)];[bezierPath addLineToPoint: CGPointMake(96, 206)];[bezierPath addLineToPoint: CGPointMake(102, 150)];[bezierPath addLineToPoint: CGPointMake(116, 150)];[bezierPath addLineToPoint: CGPointMake(127, 82)];[bezierPath addLineToPoint: CGPointMake(143, 213)];[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(0, 150);self.endPoint   = CGPointMake(160, 150);// 初始化viewUIButton *redButton       = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];redButton.center          = self.startPoint;redButton.backgroundColor = [UIColor redColor];[redButton addTarget:self action:@selector(buttonEvent) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:redButton];// CAKeyframeAnimationCAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];animation.path                 = [self path].CGPath;animation.duration             = 2.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(68, 150)];[bezierPath addLineToPoint: CGPointMake(83, 107)];[bezierPath addLineToPoint: CGPointMake(96, 206)];[bezierPath addLineToPoint: CGPointMake(102, 150)];[bezierPath addLineToPoint: CGPointMake(116, 150)];[bezierPath addLineToPoint: CGPointMake(127, 82)];[bezierPath addLineToPoint: CGPointMake(143, 213)];[bezierPath addLineToPoint: self.endPoint];return bezierPath;
}- (void)buttonEvent {// todo
}@end

细节

沿着path路径做动画相关推荐

  1. python animation path_帅气的SVG路径描边动画 (path animation) 实战应用

    这是我的一个关于SVG的应用的技术分享网站svgtrick.com,会同步一些文章到这里来,更多关于SVG技术应用可以去网站看看. 要是觉得文章还不错的话,可以多多推荐哦. 今天这篇文章来聊聊SVG路 ...

  2. UI设计师SVG动画进阶篇——路径变形动画(上篇)

    之前分享了一些自己平时整理的可以通用的SVG动画的教程基本都是最基础的变化,旋转也好,缩放也好,沿路径运动也好,只需要定义CSS3的一些动画属性值或者SVG的动画属性标签,当然,运用得当的话,依靠这些 ...

  3. CABasicAnimation,CAKeyframeAnimation,CATransition,CAAnimationGroup,UIBezierPath之间做动画的不同点和各自的使用范围。

    CABasicAnimation,CAKeyframeAnimation,CATransition,CAAnimationGroup,UIBezierPath之间做动画的不同点和各自的使用范围. CA ...

  4. ios开发——使用CALayer和Core Animation做动画效果

    一. CALayer (一). CALayer简介 在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个文本输入框.一个图标等等,这些都是UIView,其实UIV ...

  5. SVG——入门,路径变形动画

    刚学了两天svg基础,随手记个笔记,通过改变svg锚点路径创作动画效果,今天的demo是一个播放和暂停的按钮 动画的原理,无论是帧动画,还是位移动画,无非就是将一个图形从a状态转变为b状态的一个过程 ...

  6. 谷歌地图路径回放动画的实现(总结)

    因为公司有一些特殊的需求,前几天在做上一个上一个项目的时候,用到了谷歌地图,路径回放这个功能再百度地图和高德地图是有API直接可以使用的,奈何公司领导只让用谷歌地图,搜索发现网上并无多少相关文章,所以 ...

  7. 使用snap.svg实现svg路径描边动画

    使用snap.svg实现svg路径描边动画 一,snap.svg插件 在近几天,突然接到一个需求,内容是要在网页上写一个路径的动画,还需要可以随意控制动画的速度,开始于结束,本来是一个图片可以解决的问 ...

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

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

  9. java 图片动画_java在窗口中添加图片做动画,怎么一闪一闪的?

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 视频来自:优酷 在java中添加图片做动画效果,怎么一闪一闪的运动啊?怎样才能让它不闪的连续运动呢? 下面是代码,代码项目project里有两个类,一个是 ...

最新文章

  1. BAT教程 第三节(FOR命令中的变量)
  2. FlashCache初体验
  3. linux的idle命令,DBA 常用Linux命令
  4. Windows Phone Local Database Schema Upgrade Part1 - Adding new columns
  5. Upload LABS Pass-11
  6. 高性能的 socket 通讯服务器(完成端口模型--IOCP)
  7. Anonymous Shared Memory android 匿名共享内存
  8. 使用RabbitMQ做的一些工作及经验教训
  9. arcgis制作空间变化图怎么做_教程:如何使用ArcGIS10.2制作气温空间分布图
  10. html中如何通过微信加朋友,微商必看:微信添加好友的13种方法和技巧
  11. 微信小程序开发(2)—— 简单的页面登陆实现
  12. 08CMS之数据库操作
  13. 学生成绩分析系统后端函数解释(Python)
  14. 农历和阳历日期互转,Python实现
  15. android棉花糖,清甜棉花糖:安卓M/Android 6.0上手体验评测
  16. 开源究竟有什么魅力?听完这 4 个故事你也许会明白
  17. IPv6与VoIP——配置Cisco CME实现VoIP实验
  18. VS Code运行C++程序的配置过程
  19. 博士复试复旦计算机,我考上复旦大学博士之路 复旦考博复试通过记
  20. winform 窗体无法显示报错“未声明或从未赋值“解决办法

热门文章

  1. 关于c#中全局类变量的建立
  2. .NET 指南:捕获并且抛出标准的异常类型
  3. 严重: StandardServer.await: create[localhost:8005]
  4. 贪婪算法在求解最小生成树中的应用(JAVA)--Prim算法
  5. Redis-集群监控之Redis monitor
  6. linux多选项菜单脚本,linux shell 编写菜单脚本事例
  7. discuz设置用户每天回帖数_discuz回贴通知插件实现-显示用户状态设置
  8. telegr怎么连接不上_无线网密码正确但是手机连接不上wifi?
  9. 大数据技术之 Kafka (第 3 章 Kafka 架构深入 ) Kafka 消费者
  10. SpringCloud 入门教程(五): Ribbon实现客户端的负载均衡