1
私はUITextViewでAlertControllerを持っています。キーボードがあるときにUIAlertControllerスタイルのアラートUITextViewで表示
UITexViewが最初のレスポンダになると、alterはキーボードで上に移動しません。
@IBAction func showAlert(sender: AnyObject) {
let alertController = UIAlertController(title: "Hello, I'm alert! \n\n\n\n\n\n\n", message: "", preferredStyle: .alert)
let rect = CGRect(x: 15, y: 15, width: 240, height: 150)//CGRectMake(15, 50, 240, 150.0)
let textView = UITextView(frame: rect)
textView.font = UIFont(name: "Helvetica", size: 15)
textView.textColor = UIColor.lightGray
textView.backgroundColor = UIColor.white
textView.layer.borderColor = UIColor.lightGray.cgColor
textView.layer.borderWidth = 1.0
textView.text = "Enter message here"
textView.delegate = self
alertController.view.addSubview(textView)
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let action = UIAlertAction(title: "Ok", style: .default, handler: { action in
let msg = (textView.textColor == UIColor.lightGray) ? "" : textView.text
print(msg!)
})
alertController.addAction(cancel)
alertController.addAction(action)
self.present(alertController, animated: true, completion: {
textView.becomeFirstResponder()
})
}
、これが私の結果である:
これは私のコードです
解決策がありますか?彼らキーボードが表示されている場合、デフォルトでは、事前
@ keithbhunterが正しい。代わりに、 'func addTextField(configurationHandler:((UITextField) - > Void)?= nil)'のテキストフィールドを使用することもできます。これはUIAlertViewControllerによって管理されます。 –