// // NewBasicViewController.m // MingMen // // Created by 罗云飞 on 2017/3/9. // Copyright © 2017年 罗云飞. All rights reserved. // #import "NewBasicViewController.h" @interface NewBasicViewController () { UILabel *navTitleLabel; //导航标题 UIView *showView; //展示视图 引用场景:网络刷新、界面重载、提示用户 } @end @implementation NewBasicViewController @synthesize backButton; /* - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { [self setHidesBottomBarWhenPushed:NO]; } return self; } */ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.view setBackgroundColor:NewWhiteColor]; [self createNavgationBar]; } #pragma mark - 创建导航条 - (void)createNavgationBar{ self.navgationBar = [[UIView alloc] init]; [self.navgationBar setFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, NAV_HEIGHT + STATUSBAR_HEIGHT)]; [self.navgationBar setBackgroundColor:NewNavigationColor]; UIView *statusView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, STATUSBAR_HEIGHT)]; [statusView setBackgroundColor:NewNavigationColor]; [self.navgationBar addSubview:statusView]; UIImage *backButtonImage = [[UIImage imageNamed:@"navigationBackImage"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)]; backButton= [UIButton buttonWithType:UIButtonTypeCustom]; backButton.frame = CGRectMake(15, 25, 55, 30); [backButton setBackgroundColor:[UIColor clearColor]]; [backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal]; [backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside]; [self.navgationBar addSubview:backButton]; navTitleLabel = [[UILabel alloc] init]; [navTitleLabel setFrame:CGRectMake(SCREEN_WIDTH*0.2, 18.0, SCREEN_WIDTH*0.6, NAV_HEIGHT)]; [navTitleLabel setBackgroundColor:NewClearColor]; [navTitleLabel setTextAlignment:NSTextAlignmentCenter]; [navTitleLabel setFont:NewBFont(18)]; [navTitleLabel setTextColor:[UIColor whiteColor]]; [self.navgationBar addSubview:navTitleLabel]; [self.view addSubview:self.navgationBar]; } #pragma mark - 导航条Title赋值 - (void)setNavTitle:(NSString *)navTitle{ if (navTitle) { [navTitleLabel setText:navTitle]; [navTitleLabel setFont:NewBFont(18)]; }else{ [navTitleLabel setHidden:YES]; } } #pragma mark - 导航条Title赋值 可自定义Title字体大小 - (void)setNavTitles:(NSString *)navTitle font:(UIFont *)font{ if (navTitle) { [navTitleLabel setText:navTitle]; [navTitleLabel setFont:font]; }else{ [navTitleLabel setHidden:YES]; } } #pragma mark - 导航条Title取值 - (NSString*)navTitle{ return navTitleLabel.text; } #pragma mark - backButton/Tabbar 是否隐藏 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES]; //[self setHidesBottomBarWhenPushed:NO]; //UIView不渗透到导航条下面 [self setAutomaticallyAdjustsScrollViewInsets:NO]; //NSLog(@"TabBar层级:%ld",self.navigationController.viewControllers.count); if (self.navigationController.viewControllers.count <= 1) { [self setBackButtonHide:YES]; [self setTabbarHide:NO]; }else{ [self setTabbarHide:YES]; } } - (void)setTabbarHide:(BOOL)isHide{ [[NewBasicTabbarController sharedInstance].tabBar setHidden:isHide]; } #pragma mark - 返回按钮是否隐藏 - (void)setBackButtonHide:(BOOL)hide{ [backButton setHidden:hide]; } #pragma mark - 跳转与返回 - (void)pushViewController:(id)pushVc { [self.navigationController pushViewController:pushVc animated:YES]; } - (void)popViewController { [self.navigationController popViewControllerAnimated:YES]; } - (void)presentViewController:(id)presentVc { [self presentViewController:presentVc animated:YES completion:nil]; } - (void)dismissViewController { [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark 初始化展示框 - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image { if(!showView) { [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]]; [showView setHidden:NO]; [showView setBackgroundColor:NewBgGrayColor]; UIImage *NOimg = [UIImage imageNamed:image]; UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg]; [showView addSubview:tempIcon]; tempIcon.sd_layout .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f)) .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f)) .widthIs(NOimg.size.width/2.0f) .heightIs(NOimg.size.height/2.0f); UILabel *tipLab = [UILabel new]; [showView addSubview:tipLab]; [tipLab setText:text]; [tipLab setTextAlignment:NSTextAlignmentCenter]; [tipLab setTextColor:NewLightGrayColor]; [tipLab setBackgroundColor:NewClearColor]; [tipLab setFont:NewAutoFont(16.0)]; tipLab.sd_layout .leftEqualToView(showView) .rightEqualToView(showView) .topSpaceToView(tempIcon,-145.0) .heightIs(20.0); if (buttonText.length>0) { UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; [showView addSubview:button]; [button setTitle:buttonText forState:UIControlStateNormal]; [button setTitleColor:NewNavigationColor forState:UIControlStateNormal]; ViewBorderRadius(button, 16, 2, NewNavigationColor); [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside]; CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16]; button.sd_layout .leftSpaceToView(showView, (showView.width/2)-((width+35)/2)) .topSpaceToView(tipLab, 30.0) .widthIs(width+35) .heightIs(34); } } [UIView beginAnimations:@"ShowArrow" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationDuration:0.25f]; [UIView setAnimationDelegate:self]; [showView setAlpha:1.0f]; [UIView commitAnimations]; } - (void)hideReloadingview { [UIView animateWithDuration:0.25 animations:^{ showView.hidden = YES; } completion:^(BOOL finished) { for (id obj in showView.subviews) { [obj removeFromSuperview]; } showView = nil; [showView removeFromSuperview]; }]; } - (void)reloadingData{ } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end