** 效果如下**
1.有图片、有title、有动画
2.有图片、无title、无动画
usage:
** 1.初始化方法 **
+ (instancetype)initWithNormalImages:(NSArray *)normalImages selectedImages:(NSArray *)selectedImages titles:(NSArray *)titles height:(CGFloat)height;
*** 可以自定制tabbar高度、允许无文字、但是照片还是要传的,如果有无图片的需求,也可以自行改源码 ***
**2. 可以自定义以下这些属性,当然你也可以不赋值,这些属性都有默认值 **
/** tabbar背景颜色*/
@property (nonatomic, strong) UIColor *backgroundColor;
/** tabbar背景图片*/
@property (nonatomic, strong) UIImage *backgroundImage;
/** 文字未选中颜色*/
@property (nonatomic, strong) UIColor *itemNormalColor;
/** 文字选中颜色*/
@property (nonatomic, strong) UIColor *itemSelectedColor;
/** 文字字体*/
@property (nonatomic, strong) UIFont *itemFont;
/** 文字和图片间距 */
@property (nonatomic, assign) CGFloat titleMargin;
/** tabbarDelegate*/
@property (nonatomic, weak) id <TabarDelegate>delegate;
/** 是否展示动画*/
@property (nonatomic, assign) BOOL animation;
**3. 每个按钮都是个tabbarItem **
初始化:+ (instancetype)initWithImage:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title;
当item 选中,并且设置显示动画:animation = YES时,展示动画。
动画代码:
/**
* 配置WclEmitterButton
*/
- (void)setup {
CAEmitterCell *explosionCell = [CAEmitterCell emitterCell];
explosionCell.name = @"explosion";
explosionCell.alphaRange = 0.10;
explosionCell.alphaSpeed = -1.0;
explosionCell.lifetime = 0.7;
explosionCell.lifetimeRange = 0.3;
explosionCell.birthRate = 0;
explosionCell.velocity = 40.00;
explosionCell.velocityRange = 10.00;
explosionCell.scale = 0.03;
explosionCell.scaleRange = 0.02;
explosionCell.contents = (id)[UIImage imageNamed:@"Sparkle"].CGImage;
_explosionLayer = [CAEmitterLayer layer];
_explosionLayer.name = @"emitterLayer";
_explosionLayer.emitterShape = kCAEmitterLayerCircle;
_explosionLayer.emitterMode = kCAEmitterLayerOutline;
_explosionLayer.emitterSize = CGSizeMake(10, 0);
_explosionLayer.emitterCells = @[explosionCell];
_explosionLayer.renderMode = kCAEmitterLayerOldestFirst;
_explosionLayer.masksToBounds = NO;
_explosionLayer.position = CGPointMake(self.frame.size.width/2.0, self.frame.size.height/2.0);
_explosionLayer.zPosition = -1;
[self.layer addSublayer:_explosionLayer];
CAEmitterCell *chargeCell = [CAEmitterCell emitterCell];
chargeCell.name = @"charge";
chargeCell.alphaRange = 0.10;
chargeCell.alphaSpeed = -1.0;
chargeCell.lifetime = 0.3;
chargeCell.lifetimeRange = 0.1;
chargeCell.birthRate = 0;
chargeCell.velocity = -40.0;
chargeCell.velocityRange = 0.00;
chargeCell.scale = 0.03;
chargeCell.scaleRange = 0.02;
chargeCell.contents = (id)[UIImage imageNamed:@"Sparkle"].CGImage;
_chargeLayer = [CAEmitterLayer layer];
_chargeLayer.name = @"emitterLayer";
_chargeLayer.emitterShape = kCAEmitterLayerCircle;
_chargeLayer.emitterMode = kCAEmitterLayerOutline;
_chargeLayer.emitterSize = CGSizeMake(20, 0);
_chargeLayer.emitterCells = @[chargeCell];
_chargeLayer.renderMode = kCAEmitterLayerOldestFirst;
_chargeLayer.masksToBounds = NO;
_chargeLayer.position = CGPointMake(self.frame.size.width/2.0, self.frame.size.height/2.0);
_chargeLayer.zPosition = -1;
[self.layer addSublayer:_chargeLayer];
}
/**
* 开始动画
*/
- (void)animation {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
if (self.selected) {
animation.values = @[@1.5 ,@0.8, @1.0,@1.2,@1.0];
animation.duration = 0.5;
[self startAnimate];
}else
{
animation.values = @[@0.8, @1.0];
animation.duration = 0.4;
}
animation.calculationMode = kCAAnimationCubic;
[self.layer addAnimation:animation forKey:@"transform.scale"];
}
/**
* 开始喷射
*/
- (void)startAnimate {
//chareLayer开始时间
self.chargeLayer.beginTime = CACurrentMediaTime();
//chareLayer每秒喷射的80个
[self.chargeLayer setValue:@80 forKeyPath:@"emitterCells.charge.birthRate"];
//进入下一个动作
[self performSelector:@selector(explode) withObject:nil afterDelay:0.2];
}
/**
* 大量喷射
*/
- (void)explode {
//让chareLayer每秒喷射的个数为0个
[self.chargeLayer setValue:@0 forKeyPath:@"emitterCells.charge.birthRate"];
//explosionLayer开始时间
self.explosionLayer.beginTime = CACurrentMediaTime();
//explosionLayer每秒喷射的2500个
[self.explosionLayer setValue:@2500 forKeyPath:@"emitterCells.explosion.birthRate"];
//停止喷射
[self performSelector:@selector(stop) withObject:nil afterDelay:0.1];
}
/**
* 停止喷射
*/
- (void)stop {
//让chareLayer每秒喷射的个数为0个
[self.chargeLayer setValue:@0 forKeyPath:@"emitterCells.charge.birthRate"];
//explosionLayer每秒喷射的0个
[self.explosionLayer setValue:@0 forKeyPath:@"emitterCells.explosion.birthRate"];
}