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的更多相关文章
随机推荐
- 随机的标识符GUID
Guid guid = Guid.NewGuid();Console.WriteLine(guid.ToString());
- javaWeb核心技术第十一篇之Listener
监听器:所谓的监听器是指对整个WEB环境的监听,当被监视的对象发生改变时,立即调用相应的方法进行处理. 监听术语: 事件源:被监听的对象. 监听器对象:监听事件源的对象 注册或绑定:1和2结合的过程 ...
- scrapy实例:爬取天气、气温等
1.创建项目 scrapy startproject weather # weather是项目名称 scrapy crawl spidername开始运行,程序自动使用start_urls构造Requ ...
- Thymeleaf常用语法:HTML属性设置
使用Thymeleaf的属性来设置HTML属性.(1)使用th:attr属性可以修改原来HTML节点的属性:(2)th:attr属性可以同时设置多个属性:(3)每一个HTML属性都有对应的Thymel ...
- 18-搭建本地 Registry
Docker Hub 虽然非常方便,但还是有些限制,比如: 需要 internet 连接,而且下载和上传速度慢. 上传到 Docker Hub 的镜像任何人都能够访问,虽然可以用私有 reposito ...
- Linux:用户权限管理
用户与用户组的概念 超级用户 拥有对系统的最高管理权限,默认是 root 用户 普通用户 只能对自己目录下的文件进行访问和修改,具有登录系统的权限. 虚拟用户 也叫"伪"用户,这类 ...
- 昨天周末晚上没有出去,码了一小段,先留着kangkang。
昨天周末晚上没有出去,码了一小段,先留着kangkang. import numpy as npimport matplotlibmatplotlib.use('Agg')import matplot ...
- 题解:swj社会摇入魔第五课
题目链接; solution: 根据画图模拟可以知道除第一次纯下降 其余每次都是一半一半的增加 S=h+h+h/2+h/4+h/8+...; 即S=h+2h=3h #include<bits/s ...
- Vue STOP&SELF方法使用
stop属性:停止冒泡只执行到此处 self:只执行当前 代码: <!doctype html> <html lang="en"> <head> ...
- 微信小程序开发练习
微信小程序开发工具git管理 https://blog.csdn.net/qq_36672905/article/details/82887102 这个开发工具的界面和交互真的是熟悉又友好,吹爆他