gpt4 book ai didi

ios - Google Places iOS自动完成结果空间

转载 作者:行者123 更新时间:2023-12-01 16:13:53 25 4
gpt4 key购买 nike

我尝试使用Google的Autocomplete API,并使用了本教程:
https://developers.google.com/places/ios-sdk/autocomplete#add_a_search_bar_to_the_top_of_a_view

我的viewDidLoad方法包含以下内容:

[super viewDidLoad];
// google autocomplete
_resultsViewController = [[GMSAutocompleteResultsViewController alloc] init];
_resultsViewController.delegate = self;
[_resultsViewController setExtendedLayoutIncludesOpaqueBars:YES];

_searchController = [[UISearchController alloc]
initWithSearchResultsController:_resultsViewController];
_searchController.searchResultsUpdater = _resultsViewController;

[_searchController setDelegate:self];

// When UISearchController presents the results view, present it in
// this view controller, not one further up the chain.
self.definesPresentationContext = YES;

// Prevent the navigation bar from being hidden when searching.
_searchController.hidesNavigationBarDuringPresentation = NO;

self.navigationController.navigationBar.translucent = NO;
_searchController.hidesNavigationBarDuringPresentation = NO;

self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeTop;
[_searchBarContainerView addSubview:_searchController.searchBar];

[_searchController setActive:YES];

但是它显示的结果类似于图像。如何删除结果和搜索栏之间的空间?
enter image description here

最佳答案

通过执行以下操作,我设法解决了这两个问题:

首先,将.automaticallyAdjustsScrollViewInsets实例的false设置为GMSAutocompleteResultsViewController():

resultsViewController.automaticallyAdjustsScrollViewInsets = false

如果您现在运行应用程序,将会看到多余的空间已消失,但是现在第一个结果在搜索栏的下方。为了解决这个问题,我使用了 additionalSafeAreaInsets.top属性(尽管可以使用所需的任何值,但我建议将其设置为 searchBarContainerView的高度):
resultsViewController.additionalSafeAreaInsets.top = searchBarContainer.frame.height

旁注:如果支持iOS 11之前的设备,则必须将这些行包装在 #available检查中,因为 additionalSafeAreaInsets仅在iOS 11+中可用。但是,在我自己的测试中,我发现iOS 10及更低版本没有这个问题。

关于ios - Google Places iOS自动完成结果空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54968730/

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