BaseLogin_VC.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // BaseLogin_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2018/12/29.
  6. // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "BaseLogin_VC.h"
  9. @interface BaseLogin_VC ()
  10. @end
  11. @implementation BaseLogin_VC
  12. #pragma mark - Life Circle
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. //添加通知
  16. [self addObservers];
  17. }
  18. - (void)didReceiveMemoryWarning {
  19. [super didReceiveMemoryWarning];
  20. }
  21. -(void)viewWillAppear:(BOOL)animated{
  22. [super viewWillAppear:animated];
  23. // [self.navigationController setNavigationBarHidden:YES];
  24. }
  25. -(void)viewDidAppear:(BOOL)animated{
  26. [super viewDidAppear:animated];
  27. }
  28. - (void)viewWillDisappear:(BOOL)animated{
  29. [super viewWillDisappear:animated];
  30. // [self.navigationController setNavigationBarHidden:NO];
  31. }
  32. #pragma mark - Pravite Method
  33. - (void)addObservers{
  34. //监听当键盘将要出现时
  35. [[NSNotificationCenter defaultCenter] addObserver:self
  36. selector:@selector(keyboardWillShow:)
  37. name:UIKeyboardWillShowNotification
  38. object:nil];
  39. //监听当键将要退出时
  40. [[NSNotificationCenter defaultCenter] addObserver:self
  41. selector:@selector(keyboardWillHide:)
  42. name:UIKeyboardWillHideNotification
  43. object:nil];
  44. }
  45. #pragma mark -Event response
  46. -(void)keyboardWillShow:(NSNotification *)notifi{
  47. //获取键盘的高度
  48. NSDictionary *userInfo = [notifi userInfo];
  49. NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  50. CGRect keyboardRect = [value CGRectValue];
  51. CGFloat height = keyboardRect.size.height;
  52. CGFloat passwordMaxY = CGRectGetMaxY(self.passwordTF.frame);
  53. CGFloat bgMaxY = CGRectGetMaxY(self.bgImageView.frame);
  54. CGFloat subHeight = height -(bgMaxY-passwordMaxY)+10;//10为间距可改
  55. //获取键盘动画时间
  56. CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]floatValue];
  57. //键盘遮挡要上移
  58. if (subHeight > 0) {
  59. [UIView animateWithDuration:duration animations:^{
  60. self.bgImageView.transform = CGAffineTransformMakeTranslation(0, -subHeight);
  61. }];
  62. }
  63. }
  64. -(void)keyboardWillHide:(NSNotification *)notifi{
  65. //获取键盘的高度
  66. NSDictionary *userInfo = [notifi userInfo];
  67. CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]floatValue];
  68. [UIView animateWithDuration:duration animations:^{
  69. self.bgImageView.transform = CGAffineTransformIdentity;
  70. }];
  71. }
  72. #pragma mark - Lazy geter/seter
  73. -(UIImageView *)bgImageView{
  74. if (!_bgImageView) {
  75. _bgImageView = [[UIImageView alloc] init];
  76. //背景图用户可交互
  77. _bgImageView.userInteractionEnabled = YES;
  78. }
  79. return _bgImageView;
  80. }
  81. -(UIView *)containerView{
  82. if (!_containerView) {
  83. _containerView = [[UIView alloc] init];
  84. }
  85. return _containerView;
  86. }
  87. -(UIImageView *)logoImageView{
  88. if (!_logoImageView) {
  89. _logoImageView = [[UIImageView alloc] init];
  90. }
  91. return _logoImageView;
  92. }
  93. -(UITextField *)accountTF{
  94. if (!_accountTF) {
  95. _accountTF = [[UITextField alloc]init];
  96. }
  97. return _accountTF;
  98. }
  99. -(UITextField *)phoneTf{
  100. if (!_phoneTf) {
  101. _phoneTf = [[UITextField alloc]init];
  102. }
  103. return _phoneTf;
  104. }
  105. -(UITextField *)passwordTF{
  106. if (!_passwordTF) {
  107. _passwordTF = [[UITextField alloc]init];
  108. }
  109. return _passwordTF;
  110. }
  111. -(UITextField *)smsCodeTF{
  112. if (!_smsCodeTF) {
  113. _smsCodeTF = [[UITextField alloc]init];
  114. }
  115. return _smsCodeTF;
  116. }
  117. -(UITextField *)confirmPasswordTf{
  118. if (!_confirmPasswordTf) {
  119. _confirmPasswordTf = [[UITextField alloc]init];
  120. }
  121. return _confirmPasswordTf;
  122. }
  123. -(UIButton *)loginButton{
  124. if (!_loginButton) {
  125. _loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
  126. }
  127. return _loginButton;
  128. }
  129. -(UIButton *)registButton{
  130. if (!_registButton) {
  131. _registButton = [UIButton buttonWithType:UIButtonTypeCustom];
  132. }
  133. return _registButton;
  134. }
  135. -(UIButton *)resetPasswordBtn{
  136. if (!_resetPasswordBtn) {
  137. _resetPasswordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  138. }
  139. return _resetPasswordBtn;
  140. }
  141. -(UIButton *)rememberBtn{
  142. if (!_rememberBtn) {
  143. _rememberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  144. }
  145. return _rememberBtn;
  146. }
  147. -(UIButton *)backBtn{
  148. if (!_backBtn) {
  149. _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  150. }
  151. return _backBtn;
  152. }
  153. -(UILabel *)backLabel{
  154. if (!_backLabel) {
  155. _backLabel = [[UILabel alloc]init];
  156. }
  157. return _backLabel;
  158. }
  159. @end