IOS实现签到特效(散花效果)的实例代码

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

散花特效

#import <Foundation/Foundation.h>
/// 领取奖励成功
@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 <UIKit/UIKit.h>
/// 领取奖励成功提示框
@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
(0)

相关推荐

  • JavaScript动态创建link标签到head里的方法

    本文实例讲述了JavaScript动态创建link标签到head里的方法.分享给大家供大家参考.具体分析如下: 相信有很多做前端的朋友碰到过需要用 JavaScript 动态创建样式表标签--link标签.这里我们就来说说如何在浏览器中动态创建link标签. 使用 jQuery 创建 link 标签 如果你开发中喜欢用jQuery,那么用jQuery在创建link标签应该是这样的: 复制代码 代码如下: var cssURL = '/style.css',     linkTag = $('<l

  • 使用Jquery实现每日签到功能

    一直想做一个签到功能,但是百度了都没有自己想要的,所以就借着网上搜到的素材然后整合自己之前写的插件layerModel自己整合了一个,大家娱乐娱乐就好! calendar.js var calUtil = { getDaysInmonth : function(iMonth, iYear){ var dPrevDate = new Date(iYear, iMonth, 0); return dPrevDate.getDate(); }, bulidCal : function(iYear, i

  • thinkPHP实现签到功能的方法

    本文实例讲述了thinkPHP实现签到功能的方法.分享给大家供大家参考,具体如下: 数据表: CREATE TABLE `members_sign` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `uid` int(11) unsigned NOT NULL COMMENT '用户id', `days` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '连续签到的天数', `is_share`

  • 基于jquery实现日历签到功能

    在一些任务游戏.贴吧管理中都会有一个签到功能,帮助大家记录登录天数,积累等级经验,这个日历签到功能是如何实现的,本文为大家进行演. 本文实例讲述了基于jquery实现日历签到功能.分享给大家供大家参考.具体如下: 运行效果截图如下: 具体代码如下: index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml

  • php实现签到功能的方法实例分析

    本文实例讲述了php实现签到功能的方法.分享给大家供大家参考,具体如下: 首先我在数据库里建了两张表,一个是用户的积分表,一个是签到状态表,分来用来记录用户的积分数和先到状态 在用户签到状态表中我们有一个字段,last_sign_time,即上一次签到时间,每次可以签到的时候把这个时间与当前时间进行比较 如果相差为0天,则说明今天已签到(这个签到是24小时内只能签到一次,即两次签到时间要相差24小时以上).如果等于一天则今日可以签到,如果2天及其以上则说明漏签了. 通过时间戳的判断,及时更新状态

  • python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)

    baiduclient.py 复制代码 代码如下: import urllib.parseimport gzipimport jsonimport refrom http.client import HTTPConnectionfrom htmlutils import TieBaParserimport httputils as utils # 请求头headers = dict()headers["Connection"] = "keep-alive"heade

  • MYSQL实现连续签到功能断签一天从头开始(sql语句)

    1,创建测试表 CREATE TABLE `testsign` ( `userid` int(5) DEFAULT NULL, `username` varchar(20) DEFAULT NULL, `signtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `type` int(1) DEFAULT '0' COMMENT '为0表示签到数据,1表示签到日期字典数据' ) ENGIN

  • 基于文本的访客签到簿

    一个很偶然的机会,在网上看到了有人用PHP+MYSQL作了一个访客签到簿, 当时觉得很有用处所以自己也很 想搞一个.但是用MYSQL觉得有点在材小用,所以就搞了一个基于文本的访客签到簿.其功能与我在网上看 到的用MYSQL作的差不多,在这里我将其源码公布,希望它对放大网友学习PHP有所帮助.限于本人的水平, 其中定有BUG,还希望朋友发现了不要忘告诉我一下.本签到簿由要两个文件组成:一个是存放签到信息的sign.txt文件, 该文件可以由NOTEPAD来创建:第二个 是处理信息的sign.php

  • php+mysql+jquery实现日历签到功能

    在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤. 1.日历签到样式: 2.本次签到只记录本月签到数,想要查询可以写其他页面,查询所有签到记录.(功能有,非常麻烦,古没有做.) 3.前台代码 <include file="Public:menu" /> <style type="text/css"> *{margin:0;padding:

  • Python脚本实现虾米网签到功能

    本文实例讲述了Python脚本实现虾米网签到功能的方法.分享给大家供大家参考,具体如下: 概述 这个脚本完成了自动登录虾米网.签到的功能. 大致要用到urllib.urllib2.cookielib这几个模块.其实就是用python实现向指定的url去post数据. 至于我怎么知道在浏览器里面登录和签到时浏览器都向服务器post了什么数据的问题,可以用强大的chrome:F12->Network里面可以看得到.有的服务器登录成功后会让客户端浏览器跳转或者立即刷新一次页面等等,会把登录时向服务器p

随机推荐