本文介绍了如何显示搜索栏的取消按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户在搜索栏上开始编辑时,我想要隐藏我的页面的导航栏,我还想显示一个取消按钮。
完成但我的取消按钮无法访问提起UISearchBar
感谢All。
I want to hide the Navigation Bar of my page when the user start editing on the searchbar, I also want to show a cancel button.
It is done but my cancel button is not accessible when I bring up the UISearchBar Thanks to All.
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
self.navigationController.navigationBar.hidden=TRUE;
CGRect r=self.view.frame;
r.origin.y=-44;
r.size.height+=44;
self.view.frame=r;
searchBar.showsCancelButton=TRUE;
}
推荐答案
目标C
Objective C
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
self.navigationController.navigationBar.hidden = TRUE;
CGRect r = self.view.frame;
r.origin.y = -44;
r.size.height += 44;
self.view.frame = r;
[searchBar setShowsCancelButton:YES animated:YES];
}
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:NO animated:YES];
}
Swift
Swift
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
self.navigationController.navigationBar.hidden = true
var r = self.view.frame
r.origin.y = -44
r.size.height += 44
self.view.frame = r
searchBar.setShowsCancelButton(true, animated: true)
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
searchBar.setShowsCancelButton(false, animated: true)
}
这篇关于如何显示搜索栏的取消按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!