KIF checking a view overflow with the keyboard / visibility

157 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 answers

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