2017-08-02 18 views
0

最初に、私はストーリーボードがなく、すべてがプログラムです。 3つのTextFieldがあり、そのうちの1つはログインボタンの背後に隠されています(isHidden = true)。ログインボタンの下には登録ボタンがあります。登録ボタンをタップすると、ログインボタンが登録ボタンの下にスライドし、非表示のtextFieldのisHiddenプロパティはfalseに設定されます。隠しテキストフィールドは、isHiddenがfalseに設定された後に選択できません。

現在のところ、登録ボタンをタップするとログインボタンが下に移動し、テキストフィールドが表示されますが選択できなくなります。ログインボタンを選択しようとすると元の位置に戻ります。

私はまた、キーボードが表示され、再び下に移動するビューを持っていると私はこれが助けているとは思わない。

テキストフィールド:

class SplitterTextField: UITextField, UITextFieldDelegate { 

    var accessID: String! 

    required init(frame: CGRect, accessID: String) { 
     super.init(frame: frame) 
     self.accessID = accessID 
     setup() 
    } 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
    } 

    private func setup() { 
     delegate = self 
     backgroundColor = Color.textFieldBackground 
     accessibilityIdentifier = accessID 
     textAlignment = .center 
     returnKeyType = .done 
     placeholder = NSLocalizedString("\(accessID!)PlaceHolder", comment: "") 
    } 

    func textFieldShouldReturn(_ textField: UITextField) -> Bool { 
     resignFirstResponder() 
     return true 
    } 
} 

移動ボタン機能:

@objc private func registerButtonTapped() { 
    if confirmPasswordTextField.isHidden { 
     animateLoginButton() 
    } else { 
     registerNewUser() 
    } 
} 


@objc private func loginButtonTapped() { 
    if !confirmPasswordTextField.isHidden { 
     animateLoginButton() 
    } else { 
     //segue to next vc 
    } 
} 

private func animateLoginButton() { 
    if confirmPasswordTextField.isHidden { 
     moveLoginButtonDown() 
    } else { 
     moveLoginButtonUp() 
    } 
} 

private func moveLoginButtonDown() { 
    //Move loginButton down revealing confirmationPasswordTextView behind it 
    UIView.animate(withDuration: 0.3, animations: { 
     self.loginButton.frame.origin.y += Layout.loginButtonYMovement 
     self.confirmPasswordTextField.isHidden = false 
    }) 
} 

private func moveLoginButtonUp() { 
    //Move the loginButton up, when it has finished moving hide the confirmationPasswordTextView 
    UIView.animate(withDuration: 0.3, animations: { 
     self.loginButton.frame.origin.y -= Layout.loginButtonYMovement 
    }, completion: { _ in 
     self.confirmPasswordTextField.isHidden = true 
    }) 
} 

ビューコントローラのキーボード機能:

func setupKeyboard() { 
     NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(sender:)), name: NSNotification.Name.UIKeyboardWillShow,object: nil) 
     NotificationCenter.default.addObserver(self,selector: #selector(keyboardWillHide(sender:)),name: NSNotification.Name.UIKeyboardWillHide,object: nil) 

} 

@objc private func keyboardWillShow(sender: NSNotification) { 
    self.view.frame.origin.y = Layout.welcomeScreenKeyboardMovement 
} 

@objc private func keyboardWillHide(sender: NSNotification) { 
    self.view.frame.origin.y = 0 
} 

任意のアドバイスは理解されるであろう。ありがとう、私は、より多くのコンテキストが必要かどうかを教えてください。すべてのビューは制約を使用して固定され、制約を含むエラーは発生しません。

+1

このボタンを追加すると、登録ボタンが押されます。 self.view.bringSubview(toFront:confirmPasswordTextField)次に、そのフィールドを選択しようとします。 –

+0

すばらしいおかげで! textFieldは機能しますが、追加するとログインボタンが上に飛び出し、新しく公開されたテキストフィールドの下にスライドします。何か案は? – Wazza

+0

@WyneRumble登録ボタンを押すと、すべてのフィールドで同じ操作を行う必要があります。それに応じてボタンのフレームを設定しなければなりません。 –

答えて

1

登録ボタンを押すと、このコード行が追加されます。

self.view.bringSubview(toFront: confirmPasswordTextField) 

そのフィールドを選択してください。 フレームボタンが互いに干渉しないように正しく設定します。 ボタンフレームを印刷して、より理解しやすくすることができます。

+0

ありがとうたくさん:) – Wazza

+0

大歓迎:) –

関連する問題