From 900acef13065a417f18cd072df291a1728ed05b0 Mon Sep 17 00:00:00 2001 From: Cao yang Date: Tue, 17 Apr 2018 15:41:18 +0800 Subject: [PATCH] 优化登录页面键盘输入 --- ParentAssistant/ParentAssistant.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist | 2 +- ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate | Bin 254716 -> 0 bytes ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/LoginViewController.swift | 65 +++++++++++++++++++++++++++++++++++++---------------------------- ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/My.storyboard | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------- ParentAssistant/ParentAssistant/Classes/libs/LZCityPickerClass/LZCityPickerView.m | 2 +- ParentAssistant/Pods/Pods.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist | 2 +- 6 files changed, 178 insertions(+), 149 deletions(-) diff --git a/ParentAssistant/ParentAssistant.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist b/ParentAssistant/ParentAssistant.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist index d073d4a..51a860c 100644 --- a/ParentAssistant/ParentAssistant.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/ParentAssistant/ParentAssistant.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ ParentAssistant.xcscheme orderHint - 1 + 0 diff --git a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate index 2fcc234..0e47914 100644 Binary files a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate and b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/LoginViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/LoginViewController.swift index cea9bd4..7d37f45 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/LoginViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/LoginViewController.swift @@ -8,31 +8,49 @@ import UIKit //登录 -class LoginViewController: UIViewController,UITextFieldDelegate { - @IBOutlet var topView: NSLayoutConstraint! +class LoginViewController: UIViewController,UITextFieldDelegate,UIScrollViewDelegate { + + @IBOutlet weak var scrollView: UIScrollView! @IBOutlet var iconImageView: UIImageView!//系统头像 @IBOutlet var phoneTextField: UITextField!//电话号码 @IBOutlet var passwordTextField: UITextField!//密码 @IBOutlet var passwordHiddenBtn: UIButton!//查看密码按钮 @IBOutlet var loginBtn: UIButton! + + var keyShow = Bool() override func viewDidLoad() { super.viewDidLoad() + + self.scrollView.contentSize = CGSize.init(width: 0, height: screenHeight) + layoutSubViews() - + + self.phoneTextField.addTarget(self, action: #selector(textFieldChange), for: UIControlEvents.editingChanged) + self.passwordTextField.addTarget(self, action: #selector(textFieldChange), for: UIControlEvents.editingChanged) + } - override func loadView() { - super.loadView() - //防止tabbar隐藏导致页面跳一下 - self.tabBarController?.tabBar.isHidden = true - self.navigationController?.setNavigationBarHidden(false, animated: true) + + func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { + + phoneTextField.resignFirstResponder() + passwordTextField.resignFirstResponder() } - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) + + //监听输入长度,显示登录按钮状态 + @objc func textFieldChange(){ + if (phoneTextField.text?.count)!>0 && (passwordTextField.text?.count)!>0 { + loginBtn.isUserInteractionEnabled = true + loginBtn.backgroundColor = navigationColor + }else{ + loginBtn.isUserInteractionEnabled = false + loginBtn.backgroundColor = UIColor.lightGray + } } + // MARK: - 设置控件属性 func layoutSubViews(){ self.navigationItem.title = "登录" - topView.constant = (getScreenHeight()-325)/3 + passwordHiddenBtn.setImage(UIImage(named: "my_password_look"), for: UIControlState.selected) NotificationCenter.default.addObserver(self, selector: #selector(LoginViewController.keyboardWIllChange(_:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(LoginViewController.getPhoneNumber(_:)), name: NSNotification.Name(rawValue: MyPhoneNumberNotification.getPhoneNumber), object: nil) @@ -41,10 +59,15 @@ class LoginViewController: UIViewController,UITextFieldDelegate { @objc func keyboardWIllChange(_ noti: Notification){ let userInfo:NSDictionary=noti.userInfo! as NSDictionary let endFrame=(userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue + if endFrame?.origin.y == getScreenHeight() { - topView.constant = (getScreenHeight()-325)/3 + UIView.animate(withDuration: 0.5) { + self.scrollView.setContentOffset(CGPoint.init(x: 0, y: 0), animated: true) + } }else{ - topView.constant = (endFrame?.origin.y)!-375 + UIView.animate(withDuration: 0.5) { + self.scrollView.setContentOffset(CGPoint.init(x: 0, y:80), animated: true) + } } } @objc func getPhoneNumber(_ noti: Notification){ @@ -58,23 +81,9 @@ class LoginViewController: UIViewController,UITextFieldDelegate { passwordHiddenBtn.isSelected = !selected passwordTextField.isSecureTextEntry = selected } - // MARK: - 设置键盘消失 - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - self.view.endEditing(true) - } // MARK: - UITextFieldDelegate func textFieldShouldReturn(_ textField: UITextField) -> Bool { - self.view.endEditing(true) - return true - } - func textFieldDidEndEditing(_ textField: UITextField) { - if textField==passwordTextField && phoneTextField.text! != "" && passwordTextField.text! != ""{ - loginBtn.isUserInteractionEnabled = true - loginBtn.backgroundColor = UIColorFromRGB(0xC5DAFF) - }else{ - loginBtn.isUserInteractionEnabled = false - loginBtn.backgroundColor = UIColor.lightGray - } + return textField.resignFirstResponder() } func isMobilePhoneNumber(_ mobile:String)->Bool { let str="^1[0-9]{10}" diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/My.storyboard b/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/My.storyboard index 8fae4db..e36be9b 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/My.storyboard +++ b/ParentAssistant/ParentAssistant/Classes/controllers/my/Controller/My.storyboard @@ -7,6 +7,7 @@ + @@ -538,7 +539,7 @@ - + @@ -548,14 +549,16 @@ - - + + - + - - + + + + @@ -564,17 +567,89 @@ + + + + + + + + + + + + + + + + + + + + - + - + - + @@ -583,20 +658,20 @@ - + - + - + - + @@ -605,17 +680,17 @@ - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + + + + - - - + + + + @@ -750,12 +770,12 @@ - + - + @@ -977,7 +997,7 @@ - + diff --git a/ParentAssistant/ParentAssistant/Classes/libs/LZCityPickerClass/LZCityPickerView.m b/ParentAssistant/ParentAssistant/Classes/libs/LZCityPickerClass/LZCityPickerView.m index 9a07e3c..8a07c13 100755 --- a/ParentAssistant/ParentAssistant/Classes/libs/LZCityPickerClass/LZCityPickerView.m +++ b/ParentAssistant/ParentAssistant/Classes/libs/LZCityPickerClass/LZCityPickerView.m @@ -66,7 +66,7 @@ static NSInteger const lz_buttonHeight = 30; __isShowed = YES; [self._superView addSubview:self]; [UIView animateWithDuration:self.interval animations:^{ - self.frame = CGRectMake(0, lz_screenHeight - lz_pickerHeight, lz_screenWidth, lz_pickerHeight); + self.frame = CGRectMake(0, lz_screenHeight - lz_pickerHeight - 66 - 44, lz_screenWidth, lz_pickerHeight); } completion:^(BOOL finished) { if (block) { block(); diff --git a/ParentAssistant/Pods/Pods.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist b/ParentAssistant/Pods/Pods.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist index 1e7f9aa..d1b4da5 100644 --- a/ParentAssistant/Pods/Pods.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/ParentAssistant/Pods/Pods.xcodeproj/xcuserdata/caoyang.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ Alamofire.xcscheme orderHint - 0 + 1 DZNEmptyDataSet.xcscheme -- libgit2 0.21.0