** 效果如下**
1.有圖片悠瞬、有title岁经、有動畫
AnimationTabBar.gif
2.有圖片又固、無title觉阅、無動畫
AnimationTabBar1.gif
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 選中,并且設(shè)置顯示動畫: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每秒噴射的個數(shù)為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每秒噴射的個數(shù)為0個
[self.chargeLayer setValue:@0 forKeyPath:@"emitterCells.charge.birthRate"];
//explosionLayer每秒噴射的0個
[self.explosionLayer setValue:@0 forKeyPath:@"emitterCells.explosion.birthRate"];
}