zoukankan      html  css  js  c++  java
  • 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;

    }

    一天一章
  • 相关阅读:
    最大公约数与最小公倍数
    素数筛
    基础数学问题
    考试前打模板
    斐波那契公约数
    期望及期望dp
    状压dp总结
    树链剖分学习
    B君的教育
    [noip2016]愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/hangman/p/6873974.html
Copyright © 2011-2022 走看看