繁体   English   中英

搜索栏取消按钮仅在 iPad 上不可见

[英]Searchbar cancel button not visible only on iPad

首先我想说我没有在Swift找到任何好的答案。 我创建了search bar 在按钮单击它显示和取消隐藏searchbar 它工作正常,取消按钮在所有iPhones上都可见,但由于某种原因在iPad可见。 应该是什么原因造成的?

这就是我创建搜索searchbar

//Create searchbar
    func createSearchBar(){

        searchBar.showsCancelButton = true
        searchBar.tintColor = UIColor(red:0.184, green:0.996, blue:0.855, alpha:1.00)
        searchBar.placeholder = "Search brands"
        searchBar.delegate = self



        searchBar.hidden =  false
        searchBar.alpha = 0

        navigationItem.titleView = searchBar
        navigationItem.setLeftBarButtonItem(menuButton, animated: true)
        navigationItem.setRightBarButtonItem(searchButtton, animated: true)


        UIView.animateWithDuration(0.5, animations: {
            self.searchBar.alpha = 1
            }, completion: { finished in
                self.searchBar.becomeFirstResponder()
        })


    }

面对同样的一个我的项目。 我在苹果论坛上发过贴,很多开发人员评论说是 xcode 错误。 所以我为 ipad 视图手动添加了取消按钮

 func configureCancelBarButton() {
    let cancelButton = UIBarButtonItem()
    cancelButton.image = UIImage(named: "cancelButton")
    cancelButton.action = #selector(viewController.ipadCancelButton(_:))
    cancelButton.target = self
    self.navigationItem.setRightBarButtonItem(cancelButton, animated: true)
}

我之前发布了一个关于这个问题的答案。 也检查一下 :)

https://developer.apple.com/documentation/uikit/uisearchbar/1624283-showscancelbutton

对于在 iPad 上运行的应用程序,此属性的值将被忽略,并且不显示取消按钮。

苹果在文档中添加了它!

如果您不使用 UISearchbar 作为 NavigationBarItem,则 UISearchbar 的取消按钮将在 iPad 中工作。

暂无
暂无

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

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