简体   繁体   English

移至下一个响应者时键盘闪烁

[英]Keyboard blinks when moving to Next Responder

I implemented basic Next button on the Text Field using the following code: 我使用以下代码在“文本字段”上实现了基本的“下一步”按钮:

func textFieldShouldReturn(textField: UITextField) -> Bool {
    let didResign = textField.resignFirstResponder()
    if(!didResign) {
        return false
    }

    let myView = getParentView(textField)
    dispatch_async(dispatch_get_main_queue(), { myView.nextField?.contentTextField.becomeFirstResponder() })

    return true
}

What annoys me is that before nextField becomes First Responder, the keyboard disappears for a brief moment which looks ugly. 令我烦恼的是,在nextField成为“第一响应者”之前,键盘消失了一会儿,看上去很丑。

The effect is not always visible, sometimes it looks like the keyboard stayed up, sometimes it blinks fast. 该效果并不总是可见的,有时看起来像是键盘停住了,有时却快速闪烁。

Is there a way to resign first responder but still keep the keyboard up? 有什么方法可以让急救人员辞职,但仍然可以保持键盘向上转动? Move to next field whilst keeping the keyboard? 在保持键盘的同时移到下一个字段?

If you're working with UI, you should be on the main queue, so there's no need to dispatch_async to the main queue. 如果使用的是UI,则应位于主队列中,因此无需将dispatch_async分配到主队列。 Removing this code will make your code cleaner. 删除此代码将使您的代码更整洁。 The method you're implemented determines the behavior of the app when the return key is pressed. 您所实现的方法确定了按下返回键时应用程序的行为。 Resigning first responder dismisses the keyboard, so if this is not the effect you want, don't resign first responder. 辞退第一响应者会关闭键盘,因此,如果这不是您想要的效果,请不要辞退第一响应者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当它是第一响应者时,无法在UIScrollView中移动UITextView - Having trouble moving an UITextView in a UIScrollView when it's the first responder UITapGesture退出键盘响应器时可以从UITableView中进行选择的删除功能 - UITapGesture removing ability to select from UITableView when resigning keyboard responder 当特定的UITextField成为第一响应者时,打开“自定义键盘扩展” - Open Custom Keyboard Extension when specific UITextField become first responder 移动iPhone时UITableView闪烁 - UITableView blinks while moving an iPhone 键盘在UIPageVIewController页面之间闪烁 - Keyboard blinks between UIPageVIewController pages 显示键盘时移动UITextField - Moving UITextFields when keyboard shows 移动键盘时出现黑色区域 - black area when moving keyboard UITextField在键盘阻止时移动 - UITextField moving when keyboard will block it 自定义搜索执行后,UITextField成为第一响应者时,键盘会出现两次 - Keyboard appears twice when UITextField becomes first responder after custom segue performed 当新的 UITextView 被分配为第一响应者时如何防止键盘下降 - How to prevent the keyboard from lowering when a new UITextView is assigned as first responder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM