本文讲述了IOS实现签到特效(散花效果)实例代码。分享给大家供大家参考,具体如下:

散花特效

#import

/// 领取奖励成功

@interface RewardSuccess : NSObject

/**

* 成功动画

*/

+ (void)show;

@end

#import "RewardSuccess.h"

#import "RewardSuccessWindow.h"

#define EmitterColor_Red [UIColor colorWithRed:255/255.0 green:0 blue:139/255.0 alpha:1]

#define EmitterColor_Yellow [UIColor colorWithRed:251/255.0 green:197/255.0 blue:13/255.0 alpha:1]

#define EmitterColor_Blue [UIColor colorWithRed:50/255.0 green:170/255.0 blue:207/255.0 alpha:1]

@implementation RewardSuccess

+ (void)show

{

UIWindow *window = [UIApplication sharedApplication].keyWindow;

UIView *backgroundView = [[UIView alloc] initWithFrame:window.bounds];

backgroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.8];

[window addSubview:backgroundView];

RewardSuccessWindow *successWindow = [[RewardSuccessWindow alloc] initWithFrame:CGRectZero];

[backgroundView addSubview:successWindow];

//缩放

successWindow.transform=CGAffineTransformMakeScale(0.01f, 0.01f);

successWindow.alpha = 0;

[UIView animateWithDuration:0.4 animations:^{

successWindow.transform = CGAffineTransformMakeScale(1.0f, 1.0f);

successWindow.alpha = 1;

}];

//3s 消失

double delayInSeconds = 3;

dispatch_time_t delayInNanoSeconds = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);

dispatch_after(delayInNanoSeconds, dispatch_get_main_queue(), ^(void){

[UIView animateWithDuration:0.4 animations:^{

successWindow.transform = CGAffineTransformMakeScale(.3f, .3f);

successWindow.alpha = 0;

}completion:^(BOOL finished) {

[backgroundView removeFromSuperview];

}];

});

//开始粒子效果

CAEmitterLayer *emitterLayer = addEmitterLayer(backgroundView,successWindow);

startAnimate(emitterLayer);

}

CAEmitterLayer *addEmitterLayer(UIView *view,UIView *window)

{

//色块粒子

CAEmitterCell *subCell1 = subCell(imageWithColor(EmitterColor_Red));

subCell1.name = @"red";

CAEmitterCell *subCell2 = subCell(imageWithColor(EmitterColor_Yellow));

subCell2.name = @"yellow";

CAEmitterCell *subCell3 = subCell(imageWithColor(EmitterColor_Blue));

subCell3.name = @"blue";

CAEmitterCell *subCell4 = subCell([UIImage imageNamed:@"success_star"]);

subCell4.name = @"star";

CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];

emitterLayer.emitterPosition = window.center;

emitterLayer.emitterPosition = window.center;

emitterLayer.emitterSize = window.bounds.size;

emitterLayer.emitterMode = kCAEmitterLayerOutline;

emitterLayer.emitterShape = kCAEmitterLayerRectangle;

emitterLayer.renderMode = kCAEmitterLayerOldestFirst;

emitterLayer.emitterCells = @[subCell1,subCell2,subCell3,subCell4];

[view.layer addSublayer:emitterLayer];

return emitterLayer;

}

void startAnimate(CAEmitterLayer *emitterLayer)

{

CABasicAnimation *redBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.red.birthRate"];

redBurst.fromValue = [NSNumber numberWithFloat:30];

redBurst.toValue = [NSNumber numberWithFloat: 0.0];

redBurst.duration = 0.5;

redBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

CABasicAnimation *yellowBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.yellow.birthRate"];

yellowBurst.fromValue = [NSNumber numberWithFloat:30];

yellowBurst.toValue = [NSNumber numberWithFloat: 0.0];

yellowBurst.duration = 0.5;

yellowBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

CABasicAnimation *blueBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.blue.birthRate"];

blueBurst.fromValue = [NSNumber numberWithFloat:30];

blueBurst.toValue = [NSNumber numberWithFloat: 0.0];

blueBurst.duration = 0.5;

blueBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

CABasicAnimation *starBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.star.birthRate"];

starBurst.fromValue = [NSNumber numberWithFloat:30];

starBurst.toValue = [NSNumber numberWithFloat: 0.0];

starBurst.duration = 0.5;

starBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

CAAnimationGroup *group = [CAAnimationGroup animation];

group.animations = @[redBurst,yellowBurst,blueBurst,starBurst];

[emitterLayer addAnimation:group forKey:@"heartsBurst"];

}

CAEmitterCell *subCell(UIImage *image)

{

CAEmitterCell * cell = [CAEmitterCell emitterCell];

cell.name = @"heart";

cell.contents = (__bridge id _Nullable)image.CGImage;

// 缩放比例

cell.scale = 0.6;

cell.scaleRange = 0.6;

// 每秒产生的数量

// cell.birthRate = 40;

cell.lifetime = 20;

// 每秒变透明的速度

// snowCell.alphaSpeed = -0.7;

// snowCell.redSpeed = 0.1;

// 秒速

cell.velocity = 200;

cell.velocityRange = 200;

cell.yAcceleration = 9.8;

cell.xAcceleration = 0;

//掉落的角度范围

cell.emissionRange = M_PI;

cell.scaleSpeed = -0.05;

cell.alphaSpeed = -0.3;

cell.spin = 2 * M_PI;

cell.spinRange = 2 * M_PI;

return cell;

}

UIImage *imageWithColor(UIColor *color)

{

CGRect rect = CGRectMake(0, 0, 13, 17);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

@end

领取奖励成功提示框

#import

/// 领取奖励成功提示框

@interface RewardSuccessWindow : UIView

@end

#import "RewardSuccessWindow.h"

static CGFloat SuccessWindow_width = 270;

static CGFloat SuccessWindow_hight = 170;

@implementation RewardSuccessWindow

(instancetype)initWithFrame:(CGRect)frame

{

CGSize screenSize = [UIScreen mainScreen].bounds.size;

self = [super initWithFrame:CGRectMake((screenSize.width - SuccessWindow_width)/2.0 , (screenSize.height - SuccessWindow_hight)/2.0, SuccessWindow_width, SuccessWindow_hight)];

if (self)

{

[self configSubViews];

}

return self;

}

- (void)configSubViews

{

self.backgroundColor = [UIColor whiteColor];

self.layer.cornerRadius = 10;

self.layer.masksToBounds = YES;

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, SuccessWindow_width, 22)];

titleLabel.text = @"恭喜您,领取成功!";

titleLabel.font = [UIFont systemFontOfSize:19.0];

titleLabel.textAlignment = NSTextAlignmentCenter;

[self addSubview:titleLabel];

UILabel *expLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 75, SuccessWindow_width, 43)];

expLabel.font = [UIFont systemFontOfSize:15];

expLabel.textAlignment = NSTextAlignmentCenter;

[self addSubview:expLabel];

NSString *string = @"获得经验:+6";

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];

[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, string.length)];

[attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"MarkerFelt-Thin" size:35] range:NSMakeRange(5,2)];

NSShadow *shadow =[[NSShadow alloc] init];

shadow.shadowOffset = CGSizeMake(1, 3);

[attributedString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(5,2)];

[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(5,2)];

expLabel.attributedText = attributedString;

UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 135, SuccessWindow_width, 22)];

bottomLabel.text = @"可以在我的->我的奖励中查看获得奖励";

bottomLabel.font = [UIFont systemFontOfSize:13.0];

bottomLabel.textAlignment = NSTextAlignmentCenter;

bottomLabel.textColor = [UIColor colorWithRed:177/255.0 green:177/255.0 blue:177/255.0 alpha:1];

[self addSubview:bottomLabel];

}

@end

html动态散花代码,IOS实现签到特效(散花效果)的实例代码相关推荐

  1. html实现文字隐藏展开特效代码,js实现点击展开隐藏效果(实例代码)

    js实现点击展开隐藏效果(实例代码) 发布时间:2020-09-20 10:47:49 来源:脚本之家 阅读:69 作者:laozhang 本章给大家介绍用js事件冒泡实现鼠标点击显示提示框效果(代码 ...

  2. 鼠标点击时隐藏java代码,js实现点击展开隐藏效果(实例代码)

    本章给大家介绍用js事件冒泡实现鼠标点击显示提示框效果(代码实例).有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 先看看效果图: 代码实例: 事件冒泡-提示框 button { wi ...

  3. android 仿ios动画效果代码,Android仿IOS上拉下拉弹性效果的实例代码

    用过iphone的朋友相信都体验过页面上拉下拉有一个弹性的效果,使用起来用户体验很好:Android并没有给我们封装这样一个效果,我们来看下在Android里如何实现这个效果.先看效果,感觉有些时候还 ...

  4. python下雪的实例_javascript实现下雪效果【实例代码】

    原理 : 1.js动态创建DIV,指定CLASS类设置不同的背景图样式显示不同的雪花效果. 2.js获取创建的DIV并改变其top属性值,当下落的高度大于屏幕高后删除该移动div 3.好像不够完善勿喷 ...

  5. php柱状图html代码,html5生成柱状图(条形图)效果的实例代码

    下面小编就为大家分享一篇html5生成柱状图(条形图)效果的实例代码.小编觉得挺不错的,现在分享给大家,也给大家一个参考.一起跟随小编过来看看吧 XML/HTML Code复制内容到剪贴板 (func ...

  6. css玻璃雨滴效果,CSS实现雨滴动画效果的实例代码

    玻璃窗 今天我们要实现的是雨滴效果,不过实现雨滴前,我们先把毛玻璃的效果弄出来,没有玻璃窗,雨都进屋了,还有啥好敲打的. .window { position: absolute; width: 10 ...

  7. html实现的动画效果代码,CSS实现雨滴动画效果的实例代码

    玻璃窗 今天我们要实现的是雨滴效果,不过实现雨滴前,我们先把毛玻璃的效果弄出来,没有玻璃窗,雨都进屋了,还有啥好敲打的. .window { position: absolute; width: 10 ...

  8. python测试电脑性能的代码_python编程测试电脑开启最大线程数实例代码

    本文实例代码主要实现python编程测试电脑开启最大线程数,具体实现代码如下. #!/usr/bin/env python #coding=gbk import threading import ti ...

  9. Java写js的Ajax代码_用JS写的一个Ajax库(实例代码)

    myajax是一个用js编写的一个跨浏览器的ajax库,支持get, post, jsonp请求,精巧,简单. 一.发送GET请求: myajax.get({ data: {}, //参数 url: ...

最新文章

  1. java logback 使用_Java | Logback的使用配置
  2. Groovy安装与入门实例
  3. Http Get 和 Post
  4. RHCE认证培训+考试七天实录(一)
  5. Spring线程池服务
  6. Unity环境下RTMP推流+RTMP播放低延迟解决方案
  7. struts2第一个程序 Helloworld
  8. [转]# python中init和new的区别
  9. zend studio怎么连接mysql?
  10. .NET连接MySQL数据库并绑定于datagridview。
  11. 与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。
  12. 2011年计算机控制期末,2011计算机控制技术期末复习题详解
  13. 变电站计算机监控 规范,110kV变电站计算机监控系统技术规范书.docx
  14. 云通信接口更新迭代——SUBMAIL API V4正式上线
  15. win10系统如何设置局域网服务器地址,Win10怎么设置局域网IP地址
  16. php草莓派,甜品控的减脂早餐,这样做低卡又裹腹,草莓派香蕉派,好吃分享了...
  17. 使用单链表制作电子通讯录
  18. java模拟器电脑版怎么安装教程_电脑Java模拟器安装使用教程
  19. 【研究生论文写作】 思政相关题目选择题
  20. Keil工程文件建立以及.hex文件的生成

热门文章

  1. 堆排序python代码实现_python实现堆排序
  2. c盘users的用户名怎么改_怎么修改iPhone备份文件夹路径 iPhone C盘路径修改教程【详解】...
  3. mips汇编计算开方_读美国伊利诺伊理工大学计算机科学硕士能学到什么?
  4. linux下的awk程序在哪里编写,如何编写awk命令和脚本
  5. css 可编辑,如何设置DIV可编辑
  6. pq分解法中b’怎么求_14.初中数学:二元一次方程组,加减消元法怎么解?视频有详细解题步骤...
  7. 为什么要自学python_为什么那么多自学Python的后来都放弃了,总结起来就这些原因...
  8. 中高德地图只显示某一城市_Excel实用知识:从零开始,一步步制作属于你自己的三维演示地图...
  9. IIS Web 服务器/ASP.NET 运行原理基本知识概念整理
  10. [你必须知道的.NET]第三十四回,object成员,不见了!