【发布时间】:2017-10-23 12:02:15
【问题描述】:
在 iOS 11 中 UISearch 栏的高度有所增加,但我想要与 iOS 10 中相同的高度。如何做到这一点?我正在使用下面的代码来创建 searchController。
searchController = UIUtils.searchControllerInitialize(self)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.searchBar.delegate = self
viewTemp = UIView(frame: CGRect(x: 0.0, y: 64.0,width: UIScreen.main.bounds.size.width , height: 44))
viewTemp.addSubview(self.searchController.searchBar)
self.view.addSubview(viewTemp);
class func searchControllerInitialize(_ forViewController: UIViewController) -> UISearchController {
let controller = UISearchController(searchResultsController: nil)
controller.hidesNavigationBarDuringPresentation = true
// This property dismiss the background the navigation bar
controller.dimsBackgroundDuringPresentation = false
controller.definesPresentationContext = true
forViewController.definesPresentationContext = true
controller.searchBar.sizeToFit()
let topView: UIView = controller.searchBar.subviews[0] as UIView
for subView in topView.subviews {
if subView.isKind(of: NSClassFromString("UITextField")!) {
(subView as! UITextField).returnKeyType = UIReturnKeyType.search
(subView as! UITextField).enablesReturnKeyAutomatically = true
}
}
let viewS = UIView(frame: CGRect(x: 0.0, y: 0.0,width: UIScreen.main.bounds.size.width , height: 64))
viewS.backgroundColor = UIColor.DTColor()
controller.view.addSubview(viewS)
controller.hidesNavigationBarDuringPresentation = false
if #available(iOS 11.0, *) {
controller.searchBar.translatesAutoresizingMaskIntoConstraints = false
controller.searchBar.heightAnchor.constraint(equalToConstant: 44).isActive = true
}
return controller
}
【问题讨论】:
标签: uisearchbar ios11