简体   繁体   中英

Prevent UISearchBar from indenting right when tapped

In my viewDidLoad , I programmatically create a search bar. When the search field is tapped, the search bar indents to the right. Why is this happening and how do I prevent it from doing so? I am not using autolayout.

- (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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM