// // BaseLogin_VC.m // Haishenghai-master // // Created by GG on 2018/12/29. // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved. // #import "BaseLogin_VC.h" @interface BaseLogin_VC () @end @implementation BaseLogin_VC #pragma mark - Life Circle - (void)viewDidLoad { [super viewDidLoad]; //添加通知 [self addObservers]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; // [self.navigationController setNavigationBarHidden:YES]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; // [self.navigationController setNavigationBarHidden:NO]; } #pragma mark - Pravite Method - (void)addObservers{ //监听当键盘将要出现时 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; //监听当键将要退出时 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } #pragma mark -Event response -(void)keyboardWillShow:(NSNotification *)notifi{ //获取键盘的高度 NSDictionary *userInfo = [notifi userInfo]; NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [value CGRectValue]; CGFloat height = keyboardRect.size.height; CGFloat passwordMaxY = CGRectGetMaxY(self.passwordTF.frame); CGFloat bgMaxY = CGRectGetMaxY(self.bgImageView.frame); CGFloat subHeight = height -(bgMaxY-passwordMaxY)+10;//10为间距可改 //获取键盘动画时间 CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]floatValue]; //键盘遮挡要上移 if (subHeight > 0) { [UIView animateWithDuration:duration animations:^{ self.bgImageView.transform = CGAffineTransformMakeTranslation(0, -subHeight); }]; } } -(void)keyboardWillHide:(NSNotification *)notifi{ //获取键盘的高度 NSDictionary *userInfo = [notifi userInfo]; CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]floatValue]; [UIView animateWithDuration:duration animations:^{ self.bgImageView.transform = CGAffineTransformIdentity; }]; } #pragma mark - Lazy geter/seter -(UIImageView *)bgImageView{ if (!_bgImageView) { _bgImageView = [[UIImageView alloc] init]; //背景图用户可交互 _bgImageView.userInteractionEnabled = YES; } return _bgImageView; } -(UIView *)containerView{ if (!_containerView) { _containerView = [[UIView alloc] init]; } return _containerView; } -(UIImageView *)logoImageView{ if (!_logoImageView) { _logoImageView = [[UIImageView alloc] init]; } return _logoImageView; } -(UITextField *)accountTF{ if (!_accountTF) { _accountTF = [[UITextField alloc]init]; } return _accountTF; } -(UITextField *)phoneTf{ if (!_phoneTf) { _phoneTf = [[UITextField alloc]init]; } return _phoneTf; } -(UITextField *)passwordTF{ if (!_passwordTF) { _passwordTF = [[UITextField alloc]init]; } return _passwordTF; } -(UITextField *)smsCodeTF{ if (!_smsCodeTF) { _smsCodeTF = [[UITextField alloc]init]; } return _smsCodeTF; } -(UITextField *)confirmPasswordTf{ if (!_confirmPasswordTf) { _confirmPasswordTf = [[UITextField alloc]init]; } return _confirmPasswordTf; } -(UIButton *)loginButton{ if (!_loginButton) { _loginButton = [UIButton buttonWithType:UIButtonTypeCustom]; } return _loginButton; } -(UIButton *)registButton{ if (!_registButton) { _registButton = [UIButton buttonWithType:UIButtonTypeCustom]; } return _registButton; } -(UIButton *)resetPasswordBtn{ if (!_resetPasswordBtn) { _resetPasswordBtn = [UIButton buttonWithType:UIButtonTypeCustom]; } return _resetPasswordBtn; } -(UIButton *)rememberBtn{ if (!_rememberBtn) { _rememberBtn = [UIButton buttonWithType:UIButtonTypeCustom]; } return _rememberBtn; } -(UIButton *)backBtn{ if (!_backBtn) { _backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; } return _backBtn; } -(UILabel *)backLabel{ if (!_backLabel) { _backLabel = [[UILabel alloc]init]; } return _backLabel; } @end