【问题标题】:Why is there a UIToolbar left behind after resigning keyboard from search bar?为什么从搜索栏退出键盘后会留下 UIToolbar?
【发布时间】:2020-04-27 18:36:47
【问题描述】:

顺便说一句,这是以编程方式制作的。我在导航标题视图中添加了一个 UISearchBar。当控制器首次加载时,它成为第一响应者。单击时搜索栏中的取消按钮会移除键盘并返回到根视图控制器。当这种情况发生时,UIToolbar 会在整个 UIToolBar 视图的顶部留下明显的模糊。我通过 View Hierarchy 检查了它,它显示它是一个工具栏,我认为键盘底部视图是表情符号按钮和语音按钮所在的位置。我试过 resigningFirstResponder 和 endEditing(true)。两者都留下了我从未在我的应用程序中创建的工具栏。有关如何修复它的任何建议,还是我无法控制的错误?

实施,

// Setup for viewDidLoad
    private func setup() {
        // Navigation
        navigationController?.setToolbarHidden(false, animated: true)
        navigationItem.setHidesBackButton(true, animated: false)
        searchView.searchBar.delegate = self
        navigationItem.titleView = searchView.searchBar
        searchView.searchBar.becomeFirstResponder()
    }

    // When the cancel button is pressed
    public func goBackToRootController() {
        // I've used both individually and together and the problem still occurs
        searchView.searchBar.resignFirstResponder()
        searchView.searchBar.endEditing(true)
        navigationController?.popToRootViewController(animated: true)
    }

【问题讨论】:

  • 请分享您的代码

标签: ios swift uisearchbar uikeyboard programmatically-created


【解决方案1】:

问题已修复 - setToolBarHidden() 方法设置为 false。在整个应用程序中启用或显示工具栏。

【讨论】:

    猜你喜欢
    • 2013-12-03
    • 1970-01-01
    • 2022-12-18
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多