Ios UISearchController添加';s编辑时的偏移量
UISearchController在编辑开始时添加偏移量。在横向模式下,它工作得非常好,但在纵向模式下则不行 故事板中是否有任何设置可以帮助克服此问题 下面是一个动画,它在+320处运行,然后返回到-320Ios UISearchController添加';s编辑时的偏移量,ios,swift,uinavigationbar,uisearchbar,uisearchcontroller,Ios,Swift,Uinavigationbar,Uisearchbar,Uisearchcontroller,UISearchController在编辑开始时添加偏移量。在横向模式下,它工作得非常好,但在纵向模式下则不行 故事板中是否有任何设置可以帮助克服此问题 下面是一个动画,它在+320处运行,然后返回到-320 func updateSearchResultsForSearchController(searchController: UISearchController) { self.mySearchContorller.searchBar.frame=CGRectMake(-3
func updateSearchResultsForSearchController(searchController: UISearchController) {
self.mySearchContorller.searchBar.frame=CGRectMake(-320, 0, self.myTable.frame.size.width, 44.0)
}
我使用了一个序列图像板(显示细节)。附件是一个屏幕截图的序列图像板
下载了您的项目并使用它,问题似乎就在这里:
更改
self.tblSearchController.definesPresentationContext=true
至definesPresentationContext=true
此外,您正在子类化
UITableViewController
,不要创建自己的表,而是将一个表拖到情节提要中并使用它。以下是您的DetailViewController
的外观:类DetailTableViewController:UITableViewController{
var tblSearchController:UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
self.tblSearchController = UISearchController(searchResultsController: nil)
self.tableView.tableHeaderView=self.tblSearchController.searchBar
definesPresentationContext = true
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let aCell:UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell")
return aCell
}
}
您如何介绍UISearchController?它是从SplitViewController中显示还是从DetailViewController中显示?它显示为DetailViewControlRT(在UINavigationCOntroller中)。从UI中,我们可以看到它添加了320pt的偏移量(主列表的宽度)。不知道如何解决此问题,卡住了。DefinePresentationContext是问题所在,如果将其设置为true,则将覆盖当前控制器,如果当前视图控制器或其子体显示视图控制器。