简体   繁体   中英

KIF checking a view overflow with the keyboard / visibility

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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM