Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有地图应用程序行为的搜索栏(选择时导航栏全宽)_Ios_Iphone_Uinavigationbar_Uisearchbar_Uisearchdisplaycontroller - Fatal编程技术网

Ios 具有地图应用程序行为的搜索栏(选择时导航栏全宽)

Ios 具有地图应用程序行为的搜索栏(选择时导航栏全宽),ios,iphone,uinavigationbar,uisearchbar,uisearchdisplaycontroller,Ios,Iphone,Uinavigationbar,Uisearchbar,Uisearchdisplaycontroller,我正在尝试显示一个搜索栏,它的行为与本机地图应用程序中的行为完全相同。我的意思是: 我的导航栏标题视图中的搜索栏 选中时,搜索栏将占据我的导航栏的整个宽度,我将显示SearchDisplayController 到目前为止,我成功地获得了以下行为: 正如你在上面看到的,我无法让搜索栏占据整个选择的宽度。尽管如此,全宽+取消按钮似乎是与SearchDisplayController挂钩的搜索栏的默认行为,至少在搜索栏未添加到导航栏的情况下是如此 我是否错过了一个显而易见的方法?或者,当调用S

我正在尝试显示一个搜索栏,它的行为与本机地图应用程序中的行为完全相同。我的意思是:

  • 我的导航栏标题视图中的搜索栏
  • 选中时,搜索栏将占据我的导航栏的整个宽度,我将显示SearchDisplayController
到目前为止,我成功地获得了以下行为:

正如你在上面看到的,我无法让搜索栏占据整个选择的宽度。尽管如此,全宽+取消按钮似乎是与SearchDisplayController挂钩的搜索栏的默认行为,至少在搜索栏未添加到导航栏的情况下是如此


我是否错过了一个显而易见的方法?或者,当调用
SearchBar shouldBeginediting
时,我必须自己定制导航栏吗?

只要我没有完美的解决方案,我就会执行以下操作。但我仍然愿意做更好的事情

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

此外,我想知道“地图”应用程序是否真的使用了导航控制器,因为有一些自定义行为(标题视图的宽度、屏幕外左按钮的动画)让我感到惊讶。

您是否在寻找类似于
UISearchDisplayController
+
UISearchBar
的东西?

您可以设置displaysSearchBarInNavigationBar,它将占据整个导航栏。否,它已设置为
YES
。显然,如果搜索栏位于导航栏中,这还不够。谢谢。我实际上已经在使用一个UISearchDisplayController,但它的默认行为(搜索栏扩展+取消按钮幻影)似乎没有在导航栏标题视图中相应的搜索栏中“激活”。如果我没有将搜索栏放在导航栏中,我设法修复了显示控制器的框架。