沿着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(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路径做动画相关推荐
- python animation path_帅气的SVG路径描边动画 (path animation) 实战应用
这是我的一个关于SVG的应用的技术分享网站svgtrick.com,会同步一些文章到这里来,更多关于SVG技术应用可以去网站看看. 要是觉得文章还不错的话,可以多多推荐哦. 今天这篇文章来聊聊SVG路 ...
- UI设计师SVG动画进阶篇——路径变形动画(上篇)
之前分享了一些自己平时整理的可以通用的SVG动画的教程基本都是最基础的变化,旋转也好,缩放也好,沿路径运动也好,只需要定义CSS3的一些动画属性值或者SVG的动画属性标签,当然,运用得当的话,依靠这些 ...
- CABasicAnimation,CAKeyframeAnimation,CATransition,CAAnimationGroup,UIBezierPath之间做动画的不同点和各自的使用范围。
CABasicAnimation,CAKeyframeAnimation,CATransition,CAAnimationGroup,UIBezierPath之间做动画的不同点和各自的使用范围. CA ...
- ios开发——使用CALayer和Core Animation做动画效果
一. CALayer (一). CALayer简介 在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个文本输入框.一个图标等等,这些都是UIView,其实UIV ...
- SVG——入门,路径变形动画
刚学了两天svg基础,随手记个笔记,通过改变svg锚点路径创作动画效果,今天的demo是一个播放和暂停的按钮 动画的原理,无论是帧动画,还是位移动画,无非就是将一个图形从a状态转变为b状态的一个过程 ...
- 谷歌地图路径回放动画的实现(总结)
因为公司有一些特殊的需求,前几天在做上一个上一个项目的时候,用到了谷歌地图,路径回放这个功能再百度地图和高德地图是有API直接可以使用的,奈何公司领导只让用谷歌地图,搜索发现网上并无多少相关文章,所以 ...
- 使用snap.svg实现svg路径描边动画
使用snap.svg实现svg路径描边动画 一,snap.svg插件 在近几天,突然接到一个需求,内容是要在网页上写一个路径的动画,还需要可以随意控制动画的速度,开始于结束,本来是一个图片可以解决的问 ...
- [UWP]用Shape做动画(2):使用与扩展PointAnimation
上一篇几乎都在说DoubleAnimation的应用,这篇说说PointAnimation. 1. 使用PointAnimation 使用PointAnimation可以让Shape变形,但实际上没看 ...
- java 图片动画_java在窗口中添加图片做动画,怎么一闪一闪的?
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 视频来自:优酷 在java中添加图片做动画效果,怎么一闪一闪的运动啊?怎样才能让它不闪的连续运动呢? 下面是代码,代码项目project里有两个类,一个是 ...
最新文章
- BAT教程 第三节(FOR命令中的变量)
- FlashCache初体验
- linux的idle命令,DBA 常用Linux命令
- Windows Phone Local Database Schema Upgrade Part1 - Adding new columns
- Upload LABS Pass-11
- 高性能的 socket 通讯服务器(完成端口模型--IOCP)
- Anonymous Shared Memory android 匿名共享内存
- 使用RabbitMQ做的一些工作及经验教训
- arcgis制作空间变化图怎么做_教程:如何使用ArcGIS10.2制作气温空间分布图
- html中如何通过微信加朋友,微商必看:微信添加好友的13种方法和技巧
- 微信小程序开发(2)—— 简单的页面登陆实现
- 08CMS之数据库操作
- 学生成绩分析系统后端函数解释(Python)
- 农历和阳历日期互转,Python实现
- android棉花糖,清甜棉花糖:安卓M/Android 6.0上手体验评测
- 开源究竟有什么魅力?听完这 4 个故事你也许会明白
- IPv6与VoIP——配置Cisco CME实现VoIP实验
- VS Code运行C++程序的配置过程
- 博士复试复旦计算机,我考上复旦大学博士之路 复旦考博复试通过记
- winform 窗体无法显示报错“未声明或从未赋值“解决办法
热门文章
- 关于c#中全局类变量的建立
- .NET 指南:捕获并且抛出标准的异常类型
- 严重: StandardServer.await: create[localhost:8005]
- 贪婪算法在求解最小生成树中的应用(JAVA)--Prim算法
- Redis-集群监控之Redis monitor
- linux多选项菜单脚本,linux shell 编写菜单脚本事例
- discuz设置用户每天回帖数_discuz回贴通知插件实现-显示用户状态设置
- telegr怎么连接不上_无线网密码正确但是手机连接不上wifi?
- 大数据技术之 Kafka (第 3 章 Kafka 架构深入 ) Kafka 消费者
- SpringCloud 入门教程(五): Ribbon实现客户端的负载均衡