ios中天女散花效果


添加<QuartzCore/QuartzCore.h>库,一张背景图和花瓣图

#import "ViewController.h"

#import <QuartzCore/QuartzCore.h>


@interface ViewController ()


@property (nonatomic, weak) IBOutlet UIView *containerView;


@end



@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

//    cell.contents = (__bridge id)[UIImage imageNamed:@"47b5e3384e311b4f.jpg"].CGImage;

    self.view.backgroundColor = [UIColor whiteColor];

    

    

    

// =================== 背景图片 ===========================

    UIImageView * backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

    backgroundView.image = [UIImage imageNamed:@"樱花树3iPhoneLandscapeiOS8_736x414pt@3x"];

    backgroundView.contentMode = UIViewContentModeScaleAspectFill;

    [self.view addSubview:backgroundView];

    

    

// =================== 樱花飘落 ====================

    CAEmitterLayer * snowEmitterLayer = [CAEmitterLayer layer];

    snowEmitterLayer.emitterPosition = CGPointMake(100, -30);

    snowEmitterLayer.emitterSize = CGSizeMake(self.view.bounds.size.width , 0);

    snowEmitterLayer.emitterMode = kCAEmitterLayerOutline;

    snowEmitterLayer.emitterShape = kCAEmitterLayerLine;

//    snowEmitterLayer.renderMode = kCAEmitterLayerAdditive;

    

    CAEmitterCell * snowCell = [CAEmitterCell emitterCell];

    snowCell.contents = (__bridge id)[UIImage imageNamed:@"樱花瓣2"].CGImage;

    

    // 花瓣缩放比例

    snowCell.scale = 0.02;

    snowCell.scaleRange = 0.5;

    

    // 每秒产生的花瓣数量

    snowCell.birthRate = 7;

    snowCell.lifetime = 80;

    

    // 每秒花瓣变透明的速度

    snowCell.alphaSpeed = -0.01;

    

    // 秒速厘米~~

    snowCell.velocity = 40;

    snowCell.velocityRange = 60;

    

    // 花瓣掉落的角度范围

    snowCell.emissionRange = M_PI;

    

    // 花瓣旋转的速度

    snowCell.spin = M_PI_4;


    // 每个cell的颜色

//    snowCell.color = [[UIColor redColor] CGColor];

    

    // 阴影的 不透明

    snowEmitterLayer.shadowOpacity = 1;

    // 阴影化开的程度(就像墨水滴在宣纸上化开那样)

    snowEmitterLayer.shadowRadius = 8;

    // 阴影的偏移量

    snowEmitterLayer.shadowOffset = CGSizeMake(3, 3);

    // 阴影的颜色

    snowEmitterLayer.shadowColor = [[UIColor whiteColor] CGColor];

    

    

    snowEmitterLayer.emitterCells = [NSArray arrayWithObject:snowCell];

    [backgroundView.layer addSublayer:snowEmitterLayer];

    

                        

    

    


}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值