** 效果如下**
1.有圖片、有title、有動(dòng)畫(huà)

AnimationTabBar.gif
2.有圖片、無(wú)title、無(wú)動(dòng)畫(huà)

AnimationTabBar1.gif
usage:
** 1.初始化方法 **
+ (instancetype)initWithNormalImages:(NSArray *)normalImages selectedImages:(NSArray *)selectedImages titles:(NSArray *)titles height:(CGFloat)height;
*** 可以自定制tabbar高度、允許無(wú)文字、但是照片還是要傳的,如果有無(wú)圖片的需求,也可以自行改源碼 ***
**2. 可以自定義以下這些屬性,當(dāng)然你也可以不賦值,這些屬性都有默認(rèn)值 **
/** 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;
/** 是否展示動(dòng)畫(huà)*/
@property (nonatomic, assign) BOOL animation;
**3. 每個(gè)按鈕都是個(gè)tabbarItem **
初始化:+ (instancetype)initWithImage:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title;
當(dāng)item 選中,并且設(shè)置顯示動(dòng)畫(huà):animation = YES時(shí),展示動(dòng)畫(huà)。
動(dòng)畫(huà)代碼:
/**
* 配置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];
}
/**
* 開(kāi)始動(dòng)畫(huà)
*/
- (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"];
}
/**
* 開(kāi)始噴射
*/
- (void)startAnimate {
//chareLayer開(kāi)始時(shí)間
self.chargeLayer.beginTime = CACurrentMediaTime();
//chareLayer每秒噴射的80個(gè)
[self.chargeLayer setValue:@80 forKeyPath:@"emitterCells.charge.birthRate"];
//進(jìn)入下一個(gè)動(dòng)作
[self performSelector:@selector(explode) withObject:nil afterDelay:0.2];
}
/**
* 大量噴射
*/
- (void)explode {
//讓chareLayer每秒噴射的個(gè)數(shù)為0個(gè)
[self.chargeLayer setValue:@0 forKeyPath:@"emitterCells.charge.birthRate"];
//explosionLayer開(kāi)始時(shí)間
self.explosionLayer.beginTime = CACurrentMediaTime();
//explosionLayer每秒噴射的2500個(gè)
[self.explosionLayer setValue:@2500 forKeyPath:@"emitterCells.explosion.birthRate"];
//停止噴射
[self performSelector:@selector(stop) withObject:nil afterDelay:0.1];
}
/**
* 停止噴射
*/
- (void)stop {
//讓chareLayer每秒噴射的個(gè)數(shù)為0個(gè)
[self.chargeLayer setValue:@0 forKeyPath:@"emitterCells.charge.birthRate"];
//explosionLayer每秒噴射的0個(gè)
[self.explosionLayer setValue:@0 forKeyPath:@"emitterCells.explosion.birthRate"];
}