NewBasicViewController.m 7.4 KB

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