0

如何检查元素是否被呈现的键盘覆盖?假设我们有一个带有输入文本字段和“登录”按钮的登录视图,我们要确保“登录”按钮是否始终可见......当您开始在电子邮件字段中输入时,出现的键盘可能会覆盖“登录”按钮。 ..

tester().tapViewWithAccessibilityLabel("Log In")

这段代码总是点击按钮,即使它在键盘下方......

4

1 回答 1

0

你可以试试这个

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardDidShow:", name: UIKeyboardDidShowNotification, object: nil)
}

func keyboardDidShow(notification: NSNotification) {
    if let ui = notification.userInfo {
        var keyboardFrame = ui[UIKeyboardFrameEndUserInfoKey] as NSValue?
        if let kf = keyboardFrame {
            print(kf.CGRectValue())
        }
    }
}
于 2014-12-02T16:16:14.767 回答