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;

    }

    一天一章
  • 相关阅读:
    背景图像固定(背景附着)
    css背景图片位置
    2.使用第三种方式做一个多线程操作 3. 使用线程池做一个1到100的偶数之和 4.写一遍生产者与消费者模式 5 写一个字符串的单例设置模式(未完成) 6. 写一个简单工厂着模式
    简单写写
    说说JSON和JSONP区别
    web前端常见的面试题,基础知识点
    优秀网页设计_优秀Web设计的69条设计原则
    PostCSS_自动处理css3属性前缀
    用lnmp架构部署wordpress网站详细步骤
    使用html+css+js实现简易计算器
  • 原文地址:https://www.cnblogs.com/hangman/p/6873974.html
Copyright © 2011-2022 走看看