iOS - CAEmitterLayer学习笔记二

效果图:

 

流星:

#pragma mark - loading animation
- (void)showLoadingAnimation
{
    CGRect mainBounds = [[UIScreen mainScreen] bounds];
    UIView * loadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, mainBounds.size.width, mainBounds.size.height)];
    loadView.layer.contents = eaglView.layer.contents;
    loadView.tag = 1;
    [eaglView addSubview:loadView];
    [eaglView insertSubview:loadView belowSubview:_tabbarView];
    
    CAEmitterLayer * meteorEmitter = [CAEmitterLayer layer];
    meteorEmitter.emitterPosition = CGPointMake(mainBounds.size.width - 100, mainBounds.size.height/4);
    meteorEmitter.emitterSize  = CGSizeMake(200, mainBounds.size.height * 0.5);
    meteorEmitter.emitterShape = kCAEmitterLayerSphere;
    meteorEmitter.emitterMode  = kCAEmitterLayerSurface;
    meteorEmitter.renderMode   = kCAEmitterLayerAdditive;
    meteorEmitter.seed         = (arc4random()%100) + 1;
    
    CAEmitterCell * rocket = [CAEmitterCell emitterCell];
    rocket.birthRate       = 4.0;
    rocket.xAcceleration   = IPhone4?-300:-600;
    rocket.yAcceleration   = IPhone4?500:900;
    rocket.lifetime        = 0.68;
    rocket.lifetimeRange   = 0.03;
    rocket.emissionRange   = M_PI_2;
    rocket.scale           = 0.04;
    rocket.scaleRange      = 0.02;
    rocket.spinRange       = M_PI;
    rocket.contents = (id)[[UIImage imageNamed:@"metoer"] CGImage];
    
    meteorEmitter.emitterCells = @[rocket];
    [loadView.layer addSublayer:meteorEmitter];
}

 

你可能感兴趣的:(iOS - CAEmitterLayer学习笔记二)