Gau*_*rma 6 keyboard uikit uiview ipad ios
复制:
据推测,键盘颜色会改变以匹配背景.但是在这种情况下,一些键仍然很暗,所以这似乎是iOS中的一个错误(参见随附的屏幕截图).
有人关心这个吗?我们正在使用一种解决方法,包括隐藏键盘并重新显示它,但这并不理想.

此代码可以在按下主页按钮时关闭键盘,并在应用程序重新启动时将其恢复。您需要将 UITextFields委托设置为视图控制器:
class ViewController: UIViewController, UITextFieldDelegate {
private var _textField: UITextField!
private var _isFirstResponder: Bool!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "didBecomeActiveNotification:", name: UIApplicationDidBecomeActiveNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "willResignActiveNotification:", name: UIApplicationWillResignActiveNotification, object: nil)
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func didBecomeActiveNotification(nofication: NSNotification) {
if _isFirstResponder? == true {
_textField?.becomeFirstResponder()
}
}
func willResignActiveNotification(nofication: NSNotification) {
if _textField?.isFirstResponder() == true {
_isFirstResponder = true
_textField?.resignFirstResponder()
} else {
_isFirstResponder = false
}
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
_textField = textField
return true
}
}
Run Code Online (Sandbox Code Playgroud)