【发布时间】:2015-09-25 01:41:21
【问题描述】:
我以编程方式将UISearchController 添加到UIViewController 中,当UIViewController 加载时一切都很好,但是当我在UISearchController 中触摸UISearchBar 时,它移动到底部并且看起来不对。我是第一次在代码中添加 UI 元素。
override func viewDidLoad() {
super.viewDidLoad()
self.definesPresentationContext = true
searchController = ({
let controllerSearch = UISearchController(searchResultsController: nil)
controllerSearch.searchBar.frame = CGRectMake(0, 20, self.view.frame.size.width, 44)
controllerSearch.delegate = self
controllerSearch.searchBar.delegate = self
controllerSearch.searchBar.searchBarStyle = UISearchBarStyle.Default
controllerSearch.dimsBackgroundDuringPresentation = false
controllerSearch.hidesNavigationBarDuringPresentation = false
controllerSearch.searchResultsUpdater = self
controllerSearch.searchBar.sizeToFit()
self.view.addSubview(controllerSearch.searchBar)
return controllerSearch
})()
}
虽然我让控制台显示了UISearchController 的框架,但它显示了正确的结果(0.0、20.0、320.0、44.0)请任何人帮助我。
我还是试了一下,结果还是一样。
let frame = CGRectMake(0, 20, self.view.frame.size.width, 44)
controllerSearch.searchBar.frame = frame
【问题讨论】:
标签: ios xcode swift user-interface swift2