0

キャンセルをクリックしたときに uisearchDisplaycontroller の幅を変更したい。参照用にコードを追加します...

mySearchBar = [[UISearchBar alloc]init];
[mySearchBar setDelegate:self];
resName_search = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self];
resName_search.delegate = self;
resName_search.searchResultsDataSource = self;
resName_search.searchResultsDelegate = self;
[self.view addSubview:resName_search.searchBar];
[resName_search.searchBar setFrame:CGRectMake(0.0, barOriginY+79.0, 106.0, 40.0)];

それはうまく表示されます...しかし、アイテムを検索してからキャンセルボタンをクリックすると...サイズが変更されません..

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  {
   btnCuisine.hidden =YES;
   btnService.hidden =YES;
   imgDropDwn1.hidden =YES;
   imgDropDwn2.hidden =YES;
   [resName_search.searchBar  setShowsCancelButton:YES animated:NO];
   [resName_search.searchBar setFrame:CGRectMake(0.0, barOriginY+79.0, 320.0, 40.0)];
   return YES;
  } 
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  {
   NSLog(@"size changed 106.0");
   [resName_search.searchBar  setShowsCancelButton:NO animated:NO];
   [resName_search.searchBar setFrame:CGRectMake(0.0, barOriginY+79.0, 106.0, 40.0)];
   btnCuisine.hidden =NO;
   btnService.hidden =NO;
   imgDropDwn1.hidden =NO;
   imgDropDwn2.hidden =NO;
  }

私はまた、その問題の画像リンクを追加しますplzは私の問題を解決することを参照してください 画像リンク

4

1 に答える 1

1

self.searchDisplayController.searchBar.translatesAutoresizingMaskIntoConstraints を YES に設定し、setActive を NO に設定するだけです。しかし、AutoresizingMaskIntoConstraints を YES に変換することは重要ではないと思います...

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
 NSLog(@"size changed 106.0");
 self.searchDisplayController.searchBar.translatesAutoresizingMaskIntoConstraints = YES;
 [self.searchDisplayController setActive:NO animated:YES];
 [resName_search.searchBar  setShowsCancelButton:NO animated:NO];
 [resName_search.searchBar setFrame:CGRectMake(0.0, barOriginY+79.0, 106.0, 40.0)];
// mySearchBar.frame =CGRectMake(0.0, barOriginY+79.0, 106.0, 40.0);
btnCuisine.hidden =NO;
btnService.hidden =NO;
imgDropDwn1.hidden =NO;
imgDropDwn2.hidden =NO;
}

検索バーの検索中にテーブルの背景をタップしてサイズを変更しないため、searchDisplayControllerDidEndSearchデリゲートを追加します

-(void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
NSLog(@"size changed 106.0");
//    [resName_search.searchBar removeFromSuperview];
self.searchDisplayController.searchBar.translatesAutoresizingMaskIntoConstraints = YES;
[self.searchDisplayController setActive:NO animated:YES];
[resName_search.searchBar  setShowsCancelButton:NO animated:NO];
//    [self.view addSubview:resName_search.searchBar];
[resName_search.searchBar setFrame:CGRectMake(0.0, barOriginY+79.0, 106.0, 40.0)];
//    mySearchBar.frame =CGRectMake(0.0, barOriginY+79.0, 106.0, 40.0);
btnCuisine.hidden =NO;
btnService.hidden =NO;
imgDropDwn1.hidden =NO;
imgDropDwn2.hidden =NO;
}
于 2014-11-01T14:13:59.737 に答える