最近、カスタム アプリ内キーボードの作成方法を学びました。ここで、複数のカスタム キーボード間で交換できるようにしたいと考えています。ただし、textField.inputViewプロパティをリセットしても機能しないようです。
次のプロジェクトで、この問題の単純化されたバージョンを再現しました。は、UIView実際のカスタム キーボードを表します。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let blueInputView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 300))
blueInputView.backgroundColor = UIColor.blueColor()
textField.inputView = blueInputView
textField.becomeFirstResponder()
}
@IBAction func changeInputViewButtonTapped(sender: UIButton) {
let yellowInputView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 300))
yellowInputView.backgroundColor = UIColor.yellowColor()
// this doesn't cause the view to switch
textField.inputView = yellowInputView
}
}
これを実行すると、最初に期待した結果が得られます。青い入力ビューがポップアップします。
しかし、ボタンをタップして黄色の入力ビューに切り替えても、何も起こりません。なんで?これを機能させるにはどうすればよいですか?
