KIF checking a view overflow with the keyboard / visibility

174 Views Asked by At

How to check if an element is covered by presented keyboard or not? Let's say we have a login view with input text fields and button "Log In" and we want to make sure if button "Log In" is always visible... When you start typing into email field presented keyboard might cover Log In button...

tester().tapViewWithAccessibilityLabel("Log In")

this chunk of code always taps the button even it's below presented keyboard...

1

There are 1 best solutions below

0
On

you can try this

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