PeriscopeHeartAnimation
//
// ViewController.m
// PeriscopeHeartAnimation
//
// Created by ldj on 4/28/15.
// Copyright (c) 2015 ldj. All rights reserved.
// #import "ViewController.h" #define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addHeart)];
[self.view addGestureRecognizer:tap];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
} - (void)addHeart {
UIImageView *heartImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 2.0 - 14, kScreenHeight - 100, 28, 26)]; heartImageView.image = [UIImage imageNamed:@"heart"];
heartImageView.transform = CGAffineTransformMakeScale(0, 0);
[self.view addSubview:heartImageView]; CGFloat duration = 5 + (arc4random() % 5 - 2);
[UIView animateWithDuration:0.3 animations:^{
heartImageView.transform = CGAffineTransformMakeScale(1, 1);
heartImageView.transform = CGAffineTransformMakeRotation(-0.01 * (arc4random() % 20));
}];
[UIView animateWithDuration:duration animations:^{
heartImageView.alpha = 0;
}];
CAKeyframeAnimation *animation = [self createAnimation:heartImageView.frame];
animation.duration = duration;
[heartImageView.layer addAnimation:animation forKey:@"position"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((duration + 0.5) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[heartImageView removeFromSuperview];
});
} - (CAKeyframeAnimation *)createAnimation:(CGRect)frame {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef path = CGPathCreateMutable(); int height = -100 + arc4random() % 40 - 20;
int xOffset = frame.origin.x;
int yOffset = frame.origin.y;
int waveWidth = 50;
CGPoint p1 = CGPointMake(xOffset, height * 0 + yOffset);
CGPoint p2 = CGPointMake(xOffset, height * 1 + yOffset);
CGPoint p3 = CGPointMake(xOffset, height * 2 + yOffset);
CGPoint p4 = CGPointMake(xOffset, height * 2 + yOffset); CGPathMoveToPoint(path, NULL, p1.x,p1.y); if (arc4random() % 2) {
CGPathAddQuadCurveToPoint(path, NULL, p1.x - arc4random() % waveWidth, p1.y + height / 2.0, p2.x, p2.y);
CGPathAddQuadCurveToPoint(path, NULL, p2.x + arc4random() % waveWidth, p2.y + height / 2.0, p3.x, p3.y);
CGPathAddQuadCurveToPoint(path, NULL, p3.x - arc4random() % waveWidth, p3.y + height / 2.0, p4.x, p4.y);
} else {
CGPathAddQuadCurveToPoint(path, NULL, p1.x + arc4random() % waveWidth, p1.y + height / 2.0, p2.x, p2.y);
CGPathAddQuadCurveToPoint(path, NULL, p2.x - arc4random() % waveWidth, p2.y + height / 2.0, p3.x, p3.y);
CGPathAddQuadCurveToPoint(path, NULL, p3.x + arc4random() % waveWidth, p3.y + height / 2.0, p4.x, p4.y);
}
animation.path = path;
animation.calculationMode = kCAAnimationCubicPaced;
CGPathRelease(path);
return animation;
} @end
PeriscopeHeartAnimation的更多相关文章
随机推荐
- 踏实型的TOGAF企业架构学习者要学什么?
下载:本文PDF版 昨天有帮友在IT帮大本营微信群了问到 我打开ea网站的常见问题,截图回复了一下 如果让我再简单说一下该学什么,我想用下面这张图来说明 实操型的看 企业架构,从理论到实践 认证型的看 ...
- PHP mysqli_stat MySQLi 函数
定义和用法 mysqli_stat - 获取当前系统状态信息 版本支持 PHP4 PHP5 PHP7 不支持 支持 支持 语法 mysqli_stat ( mysqli $link ) mysqli_ ...
- easyUI+servlet+mysql项目总结
项目介绍 利用easyUI做前端框架,进行数据展示和用户数据收集 使用servlet做后端的控制层,并调用业务逻辑组件的业务逻辑方法,处理用户请求,根据不同处理结果返回不同的结果到前端 mysql进行 ...
- RAID&LVM有关磁盘的故障
目录 RAID&LVM有关磁盘的故障 RAID 注意:RAID硬盘失效处理--热备和热拔插 RAID实战 LVM介绍 磁盘故障 RAID&LVM有关磁盘的故障 RAID 好处:1.更多 ...
- 3-SQL过滤
# 筛选最大生命值大于6000,最大法力值大1700的英雄,然后按照二者之和从高到低进行排序 SELECT NAME , hp_max, mp_max FROM he ...
- java8-12-Optional类
Optional类 java.util.Optional 是一个容器类 避免空指针 NPE 能够快速定位空指针 常用方法: Optional.of(T t) : 创建一个 Optio ...
- 前端如何快速定位问题传参 和false
今天下午在请求接口的时候,出现了一个问题就是 传参问题 接口是请求成功的200,但是修改后返回来的却是500,这就很纳闷怎么会这样了. 经过查找,原来是因为传参问题.将有一个name:0 传递成了n ...
- 9.jenkins 集群
一. 集群配置 实际生产中,需要配置集群,来配合使用. jenkins 主节点需要安装插件 SSH Slaves 从节点(就是slave的机器)需要安装 jdk 开发包 yum install -y ...
- 201871010102-常龙龙《面向对象程序设计(java)》第十二周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- xen原理
目录:1. Xen的简介1.1 Xen的大体结构1.2 Xen对VM的称呼1.3 Xen对CPU和内存的虚拟化过程1.4 Xen对IO设备的虚拟化过程1.5 Linux Kernel对Xen的支持1. ...