gpt4 book ai didi

iphone - 如何显示搜索栏的取消按钮?

转载 作者:行者123 更新时间:2023-12-03 18:23:43 25 4
gpt4 key购买 nike

当用户开始在搜索栏上编辑时,我想隐藏页面的导航栏,我还想显示取消按钮。
已完成,但当我调出 UISearchBar 时,我的取消按钮无法访问感谢大家。

- (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;

}

最佳答案

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

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)
}

关于iphone - 如何显示搜索栏的取消按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13028665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com