• CAEmitterCell


    //

            

         CAEmitterLayer * emitter = [CAEmitterLayer layer];

        //视图大小

        emitter.frame =  self.weakView.bounds;

       //加入视图中

       [self.weakView.layer addSublayer:emitter];

     // emitter.renderMode = kCAEmitterLayerAdditive;//重叠模式

           //粒子散发位置中心

        emitter.emitterPosition = CGPointMake(emitter.frame.size.width / 2.0, emitter.frame.size.height / 2.0);

    CAEmitterCell * cell = [[CAEmitterCell alloc]init];

            //图片

        cell.contents = (__bridge id)[UIImage imageNamed:@"success_star"].CGImage;

        cell.birthRate = 50;

        cell.lifetime = 5.0;

        cell.color = [UIColor yellowColor].CGColor;

        cell.alphaSpeed = -0.4;

        cell.velocity = 50;//速度

        cell.velocityRange = 50;

        cell.emissionRange = M_PI * 2.0;

        CAEmitterCell * cell1 = [[CAEmitterCell alloc]init];

        

        //  cell.contents

        UIImage * image =imageWithColor([UIColor redColor]);

        

        UIImage *borderImg =imageWithColor([UIColor yellowColor]);

        

        UIImage * a  =[self imageWithIconName:image borderImage:borderImg border:3];

        cell1.contents= (__bridge id)a.CGImage;

        cell1.birthRate = 50;

        cell1.lifetime = 5.0;

        cell1.color = [UIColor yellowColor].CGColor;

        cell1.alphaSpeed = -0.4;

        cell1.velocity = 150;

        cell1.velocityRange = 50;

        cell1.emissionRange = M_PI * 2.0;

        

        self.imageView.image=imageWithColor([UIColor redColor]);

        //add particle template to emitter

        emitter.emitterCells = @[cell,cell1];//可以多个

    //改变边缘图像

    - (UIImage*)imageWithIconName:(UIImage*)image borderImage:(UIImage * )borderImg border:(int)border{

        //头像图片

        //    UIImage * image = [UIImage imageNamed:icon];

        //边框图片

        // UIImage * borderImg = [UIImage imageNamed:borderImage];

        //

        CGSize size = CGSizeMake(image.size.width + border, image.size.height + border);

        

        //创建图片上下文

        UIGraphicsBeginImageContextWithOptions(size, NO, 0);

        

        //绘制边框的圆

        CGContextRef context = UIGraphicsGetCurrentContext();

        CGContextAddEllipseInRect(context, CGRectMake(0, 0, size.width, size.height));

        

        //剪切可视范围

        CGContextClip(context);

        

        //绘制边框图片

        [borderImg drawInRect:CGRectMake(0, 0, size.width, size.height)];

        

        //设置头像frame

        CGFloat iconX = border / 2;

        CGFloat iconY = border / 2;

        CGFloat iconW = image.size.width;

        CGFloat iconH = image.size.height;

        

        //绘制圆形头像范围

        CGContextAddEllipseInRect(context, CGRectMake(iconX, iconY, iconW, iconH));

        

        //剪切可视范围

        CGContextClip(context);

        

        //绘制头像

        [image drawInRect:CGRectMake(iconX, iconY, iconW, iconH)];

        

        //取出整个图片上下文的图片

        UIImage *iconImage = UIGraphicsGetImageFromCurrentImageContext();

        

        return iconImage;

    }

     //颜色形成图片

    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;

    }

    一天一章
  • 相关阅读:
    Vmware14中设置Centos7静态密码
    字符串和集合截取
    通过FTP连上centos7
    centos7 离线安装mysql-5.7.21
    基于jackson注释@JsonFormat 格式化时间少8小时
    Kotlin基础学习笔记 (三)
    Android 常用开源框架源码解析 系列 (零)引言
    Kotlin基础学习笔记 (一)
    Android 常用开源框架源码解析 系列 (十一)picasso 图片框架
    Android 常用开源框架源码解析 系列 (十)Rxjava 异步框架
  • 原文地址:https://www.cnblogs.com/hangman/p/6873974.html
Copyright © 2020-2023  润新知