只要我没有完美的解决方案,我就会做以下事情。但我仍然对更好的东西持开放态度!!
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancel)];
[UIView animateWithDuration:0.1 animations:^(){
self.navigationItem.leftBarButtonItem = nil;
}];
return YES;
}
- (void)onCancel {
[self.searchController setActive:NO];
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
[UIView animateWithDuration:0.1 animations:^(){
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"OpenMenuButton.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openSideMenu:)];
}];
self.navigationItem.rightBarButtonItem =self.doneButton;
return YES;
}
此外,我想知道 Maps 应用程序是否真的使用导航控制器,因为有一些自定义行为(titleView 的宽度、leftBarButton 的动画超出屏幕)让我感到惊讶。