美文网首页
tabbar自定义移动的小点实现笔记

tabbar自定义移动的小点实现笔记

作者: 数字d | 来源:发表于2022-04-30 10:18 被阅读0次

效果:


bar.gif

实现步骤:
在自定义的tabbarcontroller中添加一个带颜色的view,UIAnimation来控制移动和显示

    [self.view addSubview:self.colorView];

-(UIView *)colorView {
    if (_colorView == nil) {
        _colorView = [[UIView alloc] initWithFrame:CGRectMake(Screen_Width / 3 / 2 -  3,Screen_Height - BottomBarHeight + 42, 6, 6)];
        _colorView.backgroundColor = yzColor(215, 100, 255);
        _colorView.layer.cornerRadius = 3;
        _colorView.layer.masksToBounds = YES;
    }
    return _colorView;
}

tabbarcontroller添加三个控制器A,B,C。从这三个控制器push到其他页面实现需要通知tabbarController将colorview隐藏掉,而在其他控制器回到这三个控制器的时候需要在viewDidLoad中将colorView展示出来
实现:在所有基础类中实现一个返回为布尔值的Block

typedef void(^YZBasicBoolBlock)(BOOL);
@property(nonatomic,copy)YZBasicBoolBlock appearBlock;


YZMainSearchBgCtl * vc = [[YZMainSearchBgCtl alloc] init];
           vc.hidesBottomBarWhenPushed = YES;
           if (self.appearBlock) {
               self.appearBlock(YES);
           }
[self.navigationController pushViewController:vc animated:YES];

- (void)viewDidAppear:(BOOL)animated  {
   [super viewDidAppear:animated];
   if (self.appearBlock) {
       self.appearBlock(NO);
   }
}

在tabbar中添加新的子Controller时,将对应的子控制器的block实现一下

#pragma mark ------ 首页YZMainViewCtl
   
   {
       YZMainViewCtl * mainVc = [[YZMainViewCtl alloc] init];
       UINavigationController * mainNaviVc = [[UINavigationController alloc] initWithRootViewController:mainVc];
       mainVc.appearBlock = ^(BOOL status) {
           if (status) {
               self.colorView.hidden = YES;
           }else {
               [self backToCenter];
           }
       };
       NSString * title = @"";
       mainNaviVc.tabBarItem.title = title;
       [mainNaviVc.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObject:selectedColor forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
       [mainNaviVc.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObject:textColor forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
       mainNaviVc.tabBarItem.image = yzTabbarImage(@"tb_1_gray");
       mainNaviVc.tabBarItem.selectedImage = yzTabbarImage(@"tb_1_color");
       [self addChildViewController:mainNaviVc];
       NSLog(@"%@",mainNaviVc);
   }

实际的backCenter

-(void)backToCenter {
   self.colorView.hidden = NO;
   [self.view bringSubviewToFront:self.colorView];
   self.colorView.center = self.colorView.center;

   // 第一个参数:延迟的时间
//    // 可以通过改变队列来改变线程
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        // 需要延迟执行的代码
//
//    });
//    [UIView animateWithDuration:0.25 animations:^{
//    }];
}

相关文章

网友评论

      本文标题:tabbar自定义移动的小点实现笔记

      本文链接:https://www.haomeiwen.com/subject/okzeyrtx.html