//添加小红点
//添加提示动画,引导用户点击
[self setViewDidLayoutSubViewsBlockInvokeOnce:YES block:^(CYLTabBarController *tabBarController) {
NSUInteger delaySeconds = 1.5;
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delaySeconds * NSEC_PER_SEC));
dispatch_after(when, dispatch_get_main_queue(), ^{
@try {
UIViewController *viewController0 = tabBarController.viewControllers[0];
// UIControl *tab0 = viewController0.cyl_tabButton;
// [tab0 cyl_showBadge];
[viewController0 cyl_setBadgeBackgroundColor:RANDOM_COLOR];
[viewController0 cyl_setBadgeCenterOffset:CGPointMake(-5, 3)];
// [viewController0 cyl_setBadgeRadius:11/2];
//以上对Badge的参数设置,需要在 cyl_showBadgeValue 调用之前执行。
[viewController0 cyl_showBadge];
// [tabBarController.viewControllers[1] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[2] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[3] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[4] cyl_setBadgeMargin:5];
[tabBarController.viewControllers[1] cyl_setBadgeBackgroundColor:RANDOM_COLOR];
[tabBarController.viewControllers[1] cyl_showBadgeValue:@"" animationType:CYLBadgeAnimationTypeScale];
[tabBarController.viewControllers[2] cyl_showBadgeValue:@"" animationType:CYLBadgeAnimationTypeShake];
NSString *testBadgeString = @"100";
// [tabBarController.viewControllers[3] cyl_setBadgeMargin:-5];
// CGSize size = [testBadgeString sizeWithAttributes:
// @{NSFontAttributeName:
// tabBarController.viewControllers[3].cyl_badgeFont}];
// float labelHeight = ceilf(size.height);
// [tabBarController.viewControllers[3] cyl_setBadgeCornerRadius:(labelHeight+ tabBarController.viewControllers[3].cyl_badgeMargin)/2];
[tabBarController.viewControllers[3] cyl_showBadgeValue:testBadgeString animationType:CYLBadgeAnimationTypeBounce];
[tabBarController.viewControllers[4] cyl_showBadgeValue:@"NEW" animationType:CYLBadgeAnimationTypeBreathe];
} @catch (NSException *exception) {}
//添加仿淘宝tabbar,第一个tab选中后有图标覆盖
if (self.selectedIndex != 0) {
return;
}
// tabBarController.selectedIndex = 1;
});
}];
- (void)tabBarController:(UITabBarController *)tabBarController didSelectControl:(UIControl *)control {
UIView *animationView;
// NSLog(@"🔴类名与方法名:%@(在第%@行),描述:control : %@ ,tabBarChildViewControllerIndex: %@, tabBarItemVisibleIndex : %@", @(__PRETTY_FUNCTION__), @(__LINE__), control, @(control.cyl_tabBarChildViewControllerIndex), @(control.cyl_tabBarItemVisibleIndex));
if ([control cyl_isTabButton]) {
//更改红标状态
if ([self.selectedViewController cyl_isShowBadge]) {
[self.selectedViewController cyl_clearBadge];
} else {
[self.selectedViewController cyl_showBadge];
}
animationView = [control cyl_tabImageView];
}
UIButton *button = CYLExternPlusButton;
BOOL isPlusButton = [control cyl_isPlusButton];
// 即使 PlusButton 也添加了点击事件,点击 PlusButton 后也会触发该代理方法。
if (isPlusButton) {
animationView = button.imageView;
}
[self addScaleAnimationOnView:animationView repeatCount:1];
// [self addRotateAnimationOnView:animationView];//暂时不推荐用旋转方式,badge也会旋转。
//添加仿淘宝tabbar,第一个tab选中后有图标覆盖
if ([control cyl_isTabButton]|| [control cyl_isPlusButton]) {
// BOOL shouldSelectedCoverShow = (self.selectedIndex == 0);
// [self setSelectedCoverShow:shouldSelectedCoverShow];
}
}
网友评论