https://live.csdn.net/v/156107
https://kunnan.blog.csdn.net/article/details/77885824
1、当进入首页时提示用户再次点击tabBar可刷新界面数据 2、刷新数据当同时旋转tabbar的图片
1、文章地址:https://kunnan.blog.csdn.net/article/details/77885824 2、应用场景:适用于购物类app的首页tabBar,以及购物券类app的首页tabBar 3、特色功能:在更新数据期间旋转tabbar的icon
https://blink.csdn.net/details/1175811
/** 记录上一次被点击按钮的tag */
@property (nonatomic, assign) NSInteger previousClickedTag;
self.tabBarController.delegate = self;
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
- (void)viewDidLoad {
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = NO;
self.view.backgroundColor = HWColor(245, 245, 245);
[self setNavigationContent];
// self.tabBarItem addObserver:<#(nonnull NSObject *)#> forKeyPath:<#(nonnull NSString *)#> options:<#(NSKeyValueObservingOptions)#> context:<#(nullable void *)#>
self.tabBarController.delegate = self;
self.previousClickedTag = 100;//默认没有点击任何tabbar
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if (tabBarController.selectedIndex == 0 && [self.tabBarItem.title isEqualToString:homeTabbarSelectedTitle]) {
//进行数据刷新
if ( self.previousClickedTag == tabBarController.selectedIndex ) {//进行了第二次点击
[self.tableView.mj_header beginRefreshing];
}
}
self.previousClickedTag = tabBarController.selectedIndex;//记录上一次按钮的点击
}
通过代理方法didSelectItem修改UITabBarItem的title ,达到选中之后和未选中的title不一样的效果
在这里插入图片描述
在这里插入图片描述
NSString * const GYQhomeTabbarTitle = @"首页";
NSString * const GYQhomeTabbarSelectedTitle = @"刷新";
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
if ([item.title isEqualToString:GYQhomeTabbarTitle]) {
item.title = GYQhomeTabbarSelectedTitle;
}else{
// 切换到其他子Tab时,将首页tab的title刷新改为《首页》
for (UITabBarItem *childView in tabBar.items) {
if ([childView.title isEqualToString:GYQhomeTabbarSelectedTitle] && childView != item) {
childView.title = GYQhomeTabbarTitle;
}
}
}
//————————————————
//版权声明:本文为CSDN博主「#公众号:iOS逆向」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
//原文链接:https://blog.csdn.net/z929118967/article/details/77885824
}
/**
是否刷新tabbar 的图片
*/
@property (nonatomic, assign) BOOL isreloadData;
/**
存储UITabBarSwappableImageView,用于旋转tabbar的图片
*/
@property (nonatomic,strong) UIView *imageView;
// 遍历tabBar上的子控件,给"UITabBarButton"类型的按钮绑定动画效果事件
//(注意:遍历添加动画事件的时机是在layoutSubviews布局子控件方法中)
- (void)layoutSubviews{
[super layoutSubviews];
for (UIControl *tabBarButton in self.subviews) {
if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[tabBarButton addTarget:self action:@selector(tabBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
}
// 动画效果(遍历UITabBarButton按钮的子控件,
//如果需要对图片添加动画,寻找"UITabBarSwappableImageView"类型的图片子控件;
////如果需要对按钮下面的文字添加动画,寻找"UITabBarButtonLabel"类型的文字子控件即可).
- (void)tabBarButtonClick:(UIControl *)tabBarButton
{
for (UIView *imageView in tabBarButton.subviews) {
if ([imageView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
if (self.block) {
self.block(imageView);
}
}}}
/**
是否更换tabbar的图片
*/
@property (nonatomic, assign) BOOL isreloadData;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有