![](/img/trans.png)
[英]UISearchBar in UISearchController slips to the right when tapped
[英]Prevent UISearchBar from indenting right when tapped
在viewDidLoad
,以編程方式創建搜索欄。 輕按搜索字段后,搜索欄會向右縮進。 為什么會發生這種情況,如何防止這種情況發生? 我沒有使用自動版式。
- (void)createSearchBar {
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.delegate = self;
[self.searchController.searchBar sizeToFit];
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;
}
您可以嘗試使用positionAdjustmentForSearchBarIcon:
或setPositionAdjustment:forSearchBarIcon:
委托調用中對搜索setPositionAdjustment:forSearchBarIcon:
消息調用: searchBarTextDidBeginEditing:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.