1
我試圖將SearchController添加到UINavigationBar。我試圖在UINavigationController的後退按鈕後設置UISearchBar的UITextField。我希望有更多的空間後退按鈕在UISearchBar中設置textfield
後,當我開始尋找它顯示爲
而我應該能夠查看後退按鈕。只有文本字段寬度應該減少。也取消後,它應該再次回到初始佈局。儘管它顯示如下:
下面是我的代碼
var searchResultController = UISearchController()
self.searchResultController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.delegate = self
controller.hidesNavigationBarDuringPresentation = false
self.navigationController?.navigationBar.addSubview(controller.searchBar)
return controller
})()
override func viewDidAppear(animated: Bool) {
for subView in searchResultController.searchBar.subviews{
for subsubView in subView.subviews {
if let textField = subsubView as? UITextField {
var bounds: CGRect
bounds = textField.frame
bounds.size.width = self.view.bounds.width - 50
}
}
}
}
請讓我知道我可以解決這個問題。
在此先感謝