ログインボタンが有効にならないのと、ログイン画面でのキーボードが出た際の処理が上手く行きません。教えてください!!```xcode
import UIKit
class LogInViewController: UIViewController{
@IBOutlet weak var EmailTextField: UITextField! @IBOutlet weak var PasswordTextField: UITextField! @IBOutlet weak var LogInTextField: UIButton! @IBOutlet weak var WarmingButton: UILabel! @IBOutlet weak var ForgetPassward: UIButton! @IBOutlet weak var NotYetGottonLabel: UILabel! @IBOutlet weak var NotYetGottonButton: UIButton! override func viewDidLoad() { super.viewDidLoad() LogInTextField.isEnabled = false WarmingButton.textColor = UIColor.red EmailTextField.delegate = self PasswordTextField.delegate = self NotificationCenter.default.addObserver(self, selector: #selector(showKeyboard), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(hideKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func showKeyboard(notification: Notification){ let keyboardFrame = (notification.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue guard let keyboardMinY = keyboardFrame?.minY else {return} let LogInTextFieldMaxY = LogInTextField.frame.maxY let distance = LogInTextFieldMaxY - keyboardMinY + 20 let transform = CGAffineTransform(translationX: 0, y: -distance) UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: { self.view.transform = transform })
}
@objc func hideKeyboard(){
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: {
self.view.transform = .identity
})
} override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { self.view.endEditing(true) }
}
extension LogInViewController: UITextFieldDelegate{
func UITextFieldDelegate(_ textField: UITextField) { let EmailIsEmpty = EmailTextField.text?.isEmpty ?? true let PasswordIsEmpty = PasswordTextField.text?.isEmpty ?? true if EmailIsEmpty || PasswordIsEmpty { LogInTextField.isEnabled = false WarmingButton.textColor = UIColor.red }else{ LogInTextField.isEnabled = true WarmingButton.textColor = UIColor.white } print("textField.text: ", textField.text) }
}
あなたの回答
tips
プレビュー