效果:
實(shí)現(xiàn)步驟:
在自定義的tabbarcontroller中添加一個(gè)帶顏色的view,UIAnimation來控制移動(dòng)和顯示
[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添加三個(gè)控制器A,B,C。從這三個(gè)控制器push到其他頁面實(shí)現(xiàn)需要通知tabbarController將colorview隱藏掉垄琐,而在其他控制器回到這三個(gè)控制器的時(shí)候需要在viewDidLoad中將colorView展示出來
實(shí)現(xiàn):在所有基礎(chǔ)類中實(shí)現(xiàn)一個(gè)返回為布爾值的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時(shí)边酒,將對(duì)應(yīng)的子控制器的block實(shí)現(xiàn)一下
#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);
}
實(shí)際的backCenter
-(void)backToCenter {
self.colorView.hidden = NO;
[self.view bringSubviewToFront:self.colorView];
self.colorView.center = self.colorView.center;
// 第一個(gè)參數(shù):延遲的時(shí)間
// // 可以通過改變隊(duì)列來改變線程
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// // 需要延遲執(zhí)行的代碼
//
// });
// [UIView animateWithDuration:0.25 animations:^{
// }];
}