iOS 8 - 如果您在iPad上按Home键并重新登录,键盘会改变颜色

Gau*_*rma 6 keyboard uikit uiview ipad ios

复制:

  1. 创建一个空白的单视图项目
  2. 将TextField拖到画布上
  3. 将TextField keyboardAppearance设置为Dark
  4. 在iPad上运行应用程序(设备或模拟器)
  5. 触摸TextField以调出键盘(它是黑暗的)
  6. 按Home,然后返回应用程序
  7. 请注意键盘会改变颜色(白色).

据推测,键盘颜色会改变以匹配背景.但是在这种情况下,一些键仍然很暗,所以这似乎是iOS中的一个错误(参见随附的屏幕截图).

有人关心这个吗?我们正在使用一种解决方法,包括隐藏键盘并重新显示它,但这并不理想.

在此输入图像描述

bub*_*uxu 0

此代码可以在按下主页按钮时关闭键盘,并在应用程序重新启动时将其恢复。您需要将 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)