NewBasicViewController.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. // NewBasicViewController.m
  3. // MingMen
  4. //
  5. // Created by 罗云飞 on 2017/3/9.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "NewBasicViewController.h"
  9. #import "UINavigationController+FDFullscreenPopGesture.h"//全局侧滑
  10. @interface NewBasicViewController ()
  11. {
  12. // UILabel *navTitleLabel; //导航标题
  13. UIView *showView; //展示视图 引用场景:网络刷新、界面重载、提示用户
  14. }
  15. @end
  16. @implementation NewBasicViewController
  17. @synthesize backButton;
  18. /*
  19. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
  20. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  21. if (self) {
  22. [self setHidesBottomBarWhenPushed:NO];
  23. }
  24. return self;
  25. }
  26. */
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self.view setBackgroundColor:NewWhiteColor];
  31. [self createNavgationBar];
  32. }
  33. #pragma mark - 创建导航条
  34. - (void)createNavgationBar{
  35. self.navgationBar = [[UIView alloc] init];
  36. [self.navgationBar setFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, NavHeader)];
  37. [self.navgationBar setBackgroundColor:[UIColor colorWithString:@"#0097F4"]];
  38. [self.view addSubview:self.navgationBar];
  39. self.statusView = [[UIView alloc] init];
  40. [self.statusView setBackgroundColor:NewWhiteColor];
  41. [self.navgationBar addSubview:self.statusView];
  42. self.statusView.sd_layout
  43. .leftEqualToView(self.navgationBar)
  44. .heightIs(STATUSBAR_HEIGHT)
  45. .rightEqualToView(self.navgationBar)
  46. .topEqualToView(self.navgationBar);
  47. UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavHeader)];
  48. [imageview setImage:NewImageNamed(@"pp")];
  49. [self.navgationBar addSubview:imageview];
  50. backButton= [UIButton buttonWithType:UIButtonTypeCustom];
  51. [backButton setBackgroundColor:[UIColor clearColor]];
  52. [backButton setImage:NewImageNamed(@"fh") forState:UIControlStateNormal];
  53. [backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
  54. [self.navgationBar addSubview:backButton];
  55. backButton.sd_layout
  56. .leftSpaceToView(self.navgationBar, 10)
  57. .heightIs(30)
  58. .widthIs(30)
  59. .bottomSpaceToView(self.navgationBar, 5);
  60. _navTitleLabel = [[UILabel alloc] init];
  61. [_navTitleLabel setBackgroundColor:NewClearColor];
  62. [_navTitleLabel setTextAlignment:NSTextAlignmentCenter];
  63. [_navTitleLabel setFont:NewBFont(18)];
  64. [_navTitleLabel setTextColor:[UIColor whiteColor]];
  65. [_navTitleLabel setSingleLineAutoResizeWithMaxWidth:0];
  66. [self.navgationBar addSubview:_navTitleLabel];
  67. _navTitleLabel.sd_layout
  68. .centerXEqualToView(self.navgationBar)
  69. .heightIs(20)
  70. .bottomSpaceToView(self.navgationBar, 10);
  71. }
  72. #pragma mark - 导航条Title赋值
  73. - (void)setNavTitle:(NSString *)navTitle{
  74. if (navTitle) {
  75. [_navTitleLabel setText:navTitle];
  76. [_navTitleLabel setFont:NewBFont(18)];
  77. }else{
  78. [_navTitleLabel setHidden:YES];
  79. }
  80. }
  81. #pragma mark - 导航条Title赋值 可自定义Title字体大小
  82. - (void)setNavTitles:(NSString *)navTitle font:(UIFont *)font{
  83. if (navTitle) {
  84. [_navTitleLabel setText:navTitle];
  85. [_navTitleLabel setFont:font];
  86. }else{
  87. [_navTitleLabel setHidden:YES];
  88. }
  89. }
  90. #pragma mark - 导航条Title取值
  91. - (NSString*)navTitle{
  92. return _navTitleLabel.text;
  93. }
  94. #pragma mark - backButton/Tabbar 是否隐藏
  95. - (void)viewWillAppear:(BOOL)animated{
  96. [super viewWillAppear:animated];
  97. [self.navigationController setNavigationBarHidden:YES];
  98. self.fd_prefersNavigationBarHidden = YES;//全局侧滑的时候父类即将显示的时候加入这句话 不会出现导航白条
  99. //[self setHidesBottomBarWhenPushed:NO];
  100. //UIView不渗透到导航条下面
  101. [self setAutomaticallyAdjustsScrollViewInsets:NO];
  102. //NSLog(@"TabBar层级:%ld",self.navigationController.viewControllers.count);
  103. if (self.navigationController.viewControllers.count <= 1) {
  104. [self setBackButtonHide:YES];
  105. [self setTabbarHide:NO];
  106. }else{
  107. [self setTabbarHide:YES];
  108. }
  109. }
  110. - (void)setTabbarHide:(BOOL)isHide{
  111. [[NewBasicTabbarController sharedInstance].tabBar setHidden:isHide];
  112. }
  113. #pragma mark - 返回按钮是否隐藏
  114. - (void)setBackButtonHide:(BOOL)hide{
  115. [backButton setHidden:hide];
  116. }
  117. #pragma mark - 跳转与返回
  118. - (void)pushViewController:(id)pushVc
  119. {
  120. [self.navigationController pushViewController:pushVc animated:YES];
  121. }
  122. - (void)popViewController
  123. {
  124. [self.navigationController popViewControllerAnimated:YES];
  125. }
  126. - (void)presentViewController:(id)presentVc
  127. {
  128. [self presentViewController:presentVc animated:YES completion:nil];
  129. }
  130. - (void)dismissViewController
  131. {
  132. [self dismissViewControllerAnimated:YES completion:nil];
  133. }
  134. #pragma mark 初始化展示框
  135. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  136. {
  137. if(!showView)
  138. {
  139. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  140. [showView setHidden:NO];
  141. [showView setBackgroundColor:NewBgGrayColor];
  142. UIImage *NOimg = [UIImage imageNamed:image];
  143. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  144. [showView addSubview:tempIcon];
  145. tempIcon.sd_layout
  146. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  147. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  148. .widthIs(NOimg.size.width/2.0f)
  149. .heightIs(NOimg.size.height/2.0f);
  150. UILabel *tipLab = [UILabel new];
  151. [showView addSubview:tipLab];
  152. [tipLab setText:text];
  153. [tipLab setTextAlignment:NSTextAlignmentCenter];
  154. [tipLab setTextColor:NewLightGrayColor];
  155. [tipLab setBackgroundColor:NewClearColor];
  156. [tipLab setFont:NewAutoFont(16.0)];
  157. tipLab.sd_layout
  158. .leftEqualToView(showView)
  159. .rightEqualToView(showView)
  160. .topSpaceToView(tempIcon,10)
  161. .heightIs(20.0);
  162. if (buttonText.length>0) {
  163. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  164. [showView addSubview:button];
  165. [button setTitle:buttonText forState:UIControlStateNormal];
  166. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  167. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  168. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  169. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  170. button.sd_layout
  171. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  172. .topSpaceToView(tipLab, 30.0)
  173. .widthIs(width+35)
  174. .heightIs(34);
  175. }
  176. }
  177. [UIView beginAnimations:@"ShowArrow" context:nil];
  178. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  179. [UIView setAnimationDuration:0.25f];
  180. [UIView setAnimationDelegate:self];
  181. [showView setAlpha:1.0f];
  182. [UIView commitAnimations];
  183. }
  184. - (void)hideReloadingview
  185. {
  186. [UIView animateWithDuration:0.25 animations:^{
  187. showView.hidden = YES;
  188. } completion:^(BOOL finished) {
  189. for (id obj in showView.subviews) {
  190. [obj removeFromSuperview];
  191. }
  192. showView = nil;
  193. [showView removeFromSuperview];
  194. }];
  195. }
  196. - (void)reloadingData{
  197. }
  198. - (void)didReceiveMemoryWarning {
  199. [super didReceiveMemoryWarning];
  200. // Dispose of any resources that can be recreated.
  201. }
  202. /*
  203. #pragma mark - Navigation
  204. // In a storyboard-based application, you will often want to do a little preparation before navigation
  205. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  206. // Get the new view controller using [segue destinationViewController].
  207. // Pass the selected object to the new view controller.
  208. }
  209. */
  210. @end