gpt4 book ai didi

ios - 如何在 UI 测试期间在 Swift 应用程序中隐藏键盘

转载 作者:IT王子 更新时间:2023-10-29 05:13:07 25 4
gpt4 key购买 nike

我刚开始在 Xcode 7 中进行 UI 测试并遇到了这个问题:

我需要在文本字段中输入文本,然后单击按钮。不幸的是,这个按钮隐藏在向文本字段输入文本时出现的键盘后面。 Xcode 正在尝试滚动以使其可见,但我的 View 不可滚动,因此失败。

我目前的解决方案是这样的:

let textField = app.textFields["placeholder"]
textField.tap()
textField.typeText("my text")
app.childrenMatchingType(.Window).elementBoundByIndex(0).tap() // hide keyboard
app.buttons["hidden button"].tap()

我可以这样做是因为我的 ViewController 正在拦截触摸:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
view.endEditing(false)
super.touchesBegan(touches, withEvent: event)
}

我对我的解决方案不是很满意,有没有其他方法可以在 UI 测试期间隐藏键盘?

最佳答案

如果您已在 中设置文本字段以退出 FirstResponder(通过 textField.resignFirstResponder()self.view.endEditing(true)) >textFieldShouldReturn() 委托(delegate)方法,然后

textField.typeText("\n")

会做的。

关于ios - 如何在 UI 测试期间在 Swift 应用程序中隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34062872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com