点击时防止UISearchBar向右缩进

时间:2015-11-09 00:27:35

标签: ios uisearchbar

在我的viewDidLoad中,我以编程方式创建了一个搜索栏。点击搜索字段后,搜索栏会向右缩进。为什么会发生这种情况?如何阻止它这样做?我没有使用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;
}

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以尝试使用positionAdjustmentForSearchBarIcon:setPositionAdjustment:forSearchBarIcon: 邮件调用委托调用中的搜索栏:searchBarTextDidBeginEditing: