KIF使用键盘/可见性检查视图溢出

时间:2014-12-02 15:33:27

标签: swift kif kif-framework

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

tester().tapViewWithAccessibilityLabel("Log In")

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

1 个答案:

答案 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())
        }
    }
}