BaseVC.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // BaseVC.m
  3. // 乐销
  4. //
  5. // Created by 隋林栋 on 2016/12/13.
  6. // Copyright © 2016年 ping. All rights reserved.
  7. //
  8. #import "BaseVC.h"
  9. //无结果页
  10. #import "NoResultView.h"
  11. //keyboard hide
  12. #import "BaseVC+KeyboardObserve.h"
  13. @interface BaseVC ()
  14. @end
  15. @implementation BaseVC
  16. - (UIView *)viewBG{
  17. if (!_viewBG) {
  18. _viewBG = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  19. _viewBG.backgroundColor = [UIColor whiteColor];
  20. }
  21. return _viewBG;
  22. }
  23. #pragma mark view did load
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. //增加侧滑
  27. if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  28. self.navigationController.interactivePopGestureRecognizer.delegate = nil;
  29. }
  30. self.automaticallyAdjustsScrollViewInsets = NO;
  31. //设置背景颜色
  32. self.view.backgroundColor = [UIColor whiteColor];
  33. [self.view insertSubview:self.viewBG atIndex:0];
  34. }
  35. #pragma mark - add observe of keyboard
  36. - (void)addObserveOfKeyboard{
  37. self.isKeyboardObserve = true;
  38. }
  39. #pragma mark view appear
  40. - (void)viewDidAppear:(BOOL)animated{
  41. [super viewDidAppear:animated];
  42. self.navigationController.interactivePopGestureRecognizer.enabled = [GlobalMethod canLeftSlide];
  43. if (self.isKeyboardObserve) {
  44. [self addKeyboardObserve];
  45. }
  46. #ifdef DEBUG
  47. NSLog(@"current vc - %@",NSStringFromClass(self.class));
  48. #endif
  49. }
  50. - (void)viewWillDisappear:(BOOL)animated{
  51. [super viewWillDisappear:animated];
  52. if (self.isKeyboardObserve) {
  53. [self removeKeyboardObserve];
  54. }
  55. }
  56. #pragma mark 懒加载
  57. - (LoadingView *)loadingView{
  58. if (_loadingView == nil) {
  59. _loadingView = [LoadingView new];
  60. }
  61. return _loadingView;
  62. }
  63. - (NoticeView *)noticeView{
  64. if (_noticeView == nil) {
  65. _noticeView = [NoticeView new];
  66. }
  67. return _noticeView;
  68. }
  69. - (NoResultView *)noResultView{
  70. if (!_noResultView) {
  71. _noResultView = [NoResultView new];
  72. }
  73. return _noResultView;
  74. }
  75. - (NoResultView *)noResultLoadingView{
  76. if (!_noResultLoadingView) {
  77. _noResultLoadingView = [NoResultView new];
  78. [_noResultLoadingView resetWithImageName:@"nocontain"];
  79. }
  80. return _noResultLoadingView;
  81. }
  82. #pragma mark 请求过程回调
  83. - (void)protocolWillRequest{
  84. [self showNoResultLoadingView];
  85. [self showLoadingView];
  86. }
  87. //show loading view
  88. - (void)showLoadingView{
  89. [self.loadingView hideLoading];
  90. if (self.isNotShowLoadingView) {
  91. return;
  92. }
  93. [self.loadingView resetFrame:CGRectMake(0, NAVIGATIONBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-NAVIGATIONBAR_HEIGHT) viewShow:self.view];
  94. }
  95. #pragma mark noresult before request
  96. - (void)showNoResultLoadingView{
  97. [self.noResultLoadingView removeFromSuperview];
  98. if(!self.isShowNoResultLoadingView)return;
  99. [self.noResultLoadingView showInView:self.view frame:CGRectMake(0, NAVIGATIONBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATIONBAR_HEIGHT)];
  100. }
  101. - (void)showNoResult{
  102. [self.noResultLoadingView removeFromSuperview];
  103. [self.noResultView removeFromSuperview];
  104. if(!self.isShowNoResult)return;
  105. [self.noResultView showInView:self.view frame:CGRectMake(0, NAVIGATIONBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATIONBAR_HEIGHT)];
  106. }
  107. - (void)protocolDidRequestSuccess{
  108. [self.loadingView hideLoading];
  109. }
  110. - (void)protocolDidRequestFailure:(NSString *)errorStr{
  111. [self.loadingView hideLoading];
  112. if (self.isNotShowNoticeView) {
  113. return;
  114. }
  115. [GlobalMethod endEditing];
  116. if ([self.view isShowInScreen]) {
  117. [self.noticeView showNotice:errorStr time:1 frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) viewShow:[UIApplication sharedApplication].keyWindow];
  118. }
  119. }
  120. #pragma mark textfield delegate
  121. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  122. [self.view endEditing:true];
  123. return true;
  124. }
  125. #pragma mark 销毁
  126. - (void)dealloc{
  127. [[NSNotificationCenter defaultCenter]removeObserver:self];
  128. }
  129. #pragma mark 改变statusbar颜色
  130. - (BOOL)prefersStatusBarHidden{
  131. return [GlobalData sharedInstance].statusHidden;
  132. }
  133. @end