gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 05:45:52 25 4
gpt4 key购买 nike

首先我想说我没有在 Swift 中找到任何好的答案。我创建了搜索栏。单击按钮时显示,取消时隐藏 searchbar。它工作正常,取消按钮在所有 iPhone 上都可见,但由于某些原因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 View 手动添加了取消按钮

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

我之前发布了关于这个问题的答案。 Check that too . :)

关于swift - 搜索栏取消按钮仅在 iPad 上不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39215587/

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