如何检查元素是否被提供的键盘覆盖? 假设我们有一个带有输入文本字段和“登录”按钮的登录视图,我们想确保按钮“登录”始终可见... 当您开始输入电子邮件字段时,显示的键盘可能会显示登录按钮...
tester().tapViewWithAccessibilityLabel("Log In")
这段代码总是轻敲按钮,即使它在键盘下方......
答案 0 :(得分: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())
}
}
}