当前界面最上面添加视图(UIWimdow)

-(void)windowAddPushVc:(UIView *)pushView WithTitle:(NSString *)title {

UIWindow *window = [UIApplication sharedApplication].keyWindow;

UINavigationBar *navigationBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];

UILabel *label = [UILabel rf_labelWithFontName:kFontPingFangMedium FontSize:36 TextAligent:NSTextAlignmentCenter TextColor:[UIColor whiteColor] CanChangeLine:NO];

label.text = title;

[navigationBar addSubview:label];

[label mas_makeConstraints:^(MASConstraintMaker *make) {

make.centerX.mas_equalTo(navigationBar);

make.centerY.mas_equalTo(navigationBar).offset(10);

}];

navigationBar.backgroundColor = kGlobelMainColor;

//添加导航栏的阴影效果

navigationBar.layer.shadowOpacity = 0.26;

navigationBar.layer.shadowOffset = CGSizeMake(0, 3);

navigationBar.layer.shadowColor = HexColor(0x000000).CGColor;

//添加返回按钮

[self addBackBtn:navigationBar];

pushView.tag = 1099;

navigationBar.tag = 1098;

pushView.frame = CGRectMake(0, 64, kScreenWidth, kScreenHeight);

navigationBar.frame = CGRectMake(0, 0, kScreenWidth, 64);

[window addSubview:pushView];

[window addSubview:navigationBar];

}

- (void)addBackBtn:(UINavigationBar *)navigationBar

{

//设置导航栏的返回按钮

RFNavButton *backBtn = [[RFNavButton alloc]initWithFrame:CGRectMake(10, 32, kFitW(100), 20)];

[backBtn setImage:[UIImage imageNamed:@"nav_backarrow_icon"] forState:UIControlStateNormal];

backBtn.titleLabel.font = [UIFont fontWithName:kFontPingFangRegular size:kFitFontSize(28)];

[backBtn setTitle:@"返回" forState:UIControlStateNormal];

[backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];

[navigationBar addSubview:backBtn];

}

//导航栏返回按钮的响应事件

- (void)backBtnClick:(UIButton *)btn

{

//只要是从消息在详情界面返回时,通知总的消息列表进行数据的刷新

[[NSNotificationCenter defaultCenter]postNotificationName:kPushListReload object:nil];

UIWindow *window = [UIApplication sharedApplication].keyWindow;

UIView *pushView  =  [window viewWithTag:1099];

UIView *navgationBar  = [window viewWithTag:1098];

[UIView animateWithDuration:0.5 animations:^{

pushView.alpha = 0;

navgationBar.alpha = 0;

}

completion:^(BOOL finished) {

[pushView removeFromSuperview];

[navgationBar removeFromSuperview];

}];

}

获取带有tabbar的控制器的最外层控制器

//获取当前的控制器

-(UIViewController *)gerCurrentVc{

UIViewController *rootVc = [UIApplication sharedApplication].keyWindow.rootViewController;

UIViewController *view = rootVc.childViewControllers[0];

RFTabBarController *tabbarView = (RFTabBarController *)view.presentedViewController;

UIViewController *rootNav = tabbarView.childViewControllers[tabbarView.selectedIndex];

UIViewController *currentVc = rootNav.childViewControllers[rootNav.childViewControllers.count-1];

return currentVc;

}

上一篇:Entity Framework 的小实例:在项目中添加一个实体类,并做插入操作


下一篇:MongoDB 3.4 安装以 Windows 服务方式运行