2
所以我有上有一個「後退」按鈕,導航欄和一個UISearchBar了這條正確的:隱藏/顯示後退按鈕上的導航欄時,搜索欄打開/關閉
[輸入圖像描述這裏] [1]
當的UISearchBar打開/節目,取消按鈕隱藏/顯示:
[在這裏輸入的形象描述] [2]
中的UISearchBar打開時,我要的是,我希望它基本上「覆蓋」後退按鈕。當它關閉時,我想讓它「揭開」後退按鈕。這是我到目前爲止的代碼:
#import "SearchViewController.h"
@interface SearchViewController()
@end
- (void)viewDidLoad {
[super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
UISearchBar *searchBar = [UISearchBar new];
searchBar.showsCancelButton = NO;
[searchBar sizeToFit];
searchBar.delegate = self;
self.navigationItem.titleView = searchBar;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:YES animated:YES];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:NO animated:YES];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
[searchBar setShowsCancelButton:NO animated:YES];
}
@end
我已經嘗試了做:在searchBarTextDidBeginEditing/searchBarTextDidEndEditing self.navigationItem.hidesBackButton = NO/YES;
但離開那個地方後退按鈕是空的!
[輸入圖像描述這裏] [3]
有沒有一種方法可以讓搜索欄擴展到後退按鈕?謝謝!
這並沒有幫助我的情況。但是,我靠得更近,但是當我重新顯示後退按鈕時,箭頭丟失。你能幫助我嗎?我已更新我的問題 – user1282637
謝謝,我會盡快嘗試 – user1282637