[置顶] iOS中tabBar按钮再次点击实现界面刷新
2017-09-07 19:47
579 查看
/** 记录上一次被点击按钮的tag */ @property (nonatomic, assign) NSInteger previousClickedTag;
- (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不一样的效果
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{ if ([item.title isEqualToString:GYQhomeTabbarTitle]) { item.title = homeTabbarSelectedTitle; }else{ for (UITabBarItem *childView in tabBar.items) { if ([childView.title isEqualToString:GYQhomeTabbarSelectedTitle] && childView != item) { childView.title = homeTabbarTitle; } } } }
旋转tabbar 的图片
self.previousClickedTag = 100;//默认没有点击任何tabbar HWTabBar *tabBar = (HWTabBar*)self.tabBarController.tabBar; [tabBar setBlock:^(UIView * imageView){ if (self.isreloadData) { self.imageView = imageView; CABasicAnimation * rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //让其在z轴旋转 rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];//旋转角度 rotationAnimation.duration = 2; //旋转周期 rotationAnimation.cumulative = YES;//旋转累加角度 rotationAnimation.repeatCount = 100000;//旋转次数 [imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; } }]; } -(void)stopRotate { [self.imageView.layer removeAllAnimations]; } - (void)setIsreloadData:(BOOL)isreloadData{ _isreloadData = isreloadData; if (!isreloadData) { [self stopRotate]; } }
//进行数据刷新 if ( self.previousClickedTag == tabBarController.selectedIndex ) {//进行了第二次点击 [self.tableView.mj_header beginRefreshing]; self.isreloadData = YES; }
监听事件的点击
// 遍历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); } }}}
相关文章推荐
- iOS开发中TabBar再次点击实现刷新效果
- ios开发-UI基础-应用管理(单纯界面)改进5-使用代理实现监听下载按钮的点击(delegate)
- [置顶] ExtJs4.2 登陆界面(点击验证码自动刷新,label实现click事件)
- iOS不得姐项目--TabBar的重复点击实现当前模块刷新;状态栏点击实现当前模块回滚到最顶部
- ios:点击tabbar中间按钮弹出菜单(swift 3实现)
- ios开发:怎么实现点击一个按钮,跳转到一个新的界面
- 重复点击主界面(TabBar)按钮刷新界面--点击状态栏回到顶部
- iOS Object-C 响应者链实现cell中的按钮点击后,导航栏push新的界面
- ios开发:怎么实现点击一个按钮,跳转到一个新的界面,并回退到上一界面
- iOS实现tableViewCell或collectionCell中点击界面按钮跳转
- iOS -- 点击button实现tabbar视图控制器跳转
- iOS中给自定义tabBar的按钮添加点击放大缩小的动画效果
- ASP.NET UpdatePanel实现点击按钮无刷新且执行js脚本
- swing初始化一个JFrame实现点击A界面的一个按钮,显示B界面,无论点击多少次,都只显示一个B界面
- ios 实现微信的非最近会话聊天界面的返回按钮
- 点击对话框上的按钮,实现弹出页面,页面在本界面显示?
- 图片点击放大,再次点击返回原视图.完美封装,一个类一句代码即可调用.IOS完美实现
- 微信公众号开发 实现点击返回按钮就返回到聊天界面
- iOS 点击键盘上的“Next”按钮实现文本框焦点跳转
- 利用runtime懒人实现iOS 防止按钮连续点击 连续响应事件,可以自己设置时间间隔,拖进工程中立即生效