Ios 防止UISearchBar在敲击时向右缩进

Ios 防止UISearchBar在敲击时向右缩进,ios,uisearchbar,Ios,Uisearchbar,在我的viewDidLoad中,我以编程方式创建了一个搜索栏。点击搜索字段时,搜索栏向右缩进。为什么会发生这种情况?我如何防止这种情况发生?我没有使用自动布局 - (void)createSearchBar { self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; self.searchController.searchResultsUpdater = s

在我的
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;
}

您可以尝试使用
位置调整forSearchBarIcon:
设置位置调整:forSearchBarIcon:

对代理调用中的搜索栏的消息调用:
searchbartextdebeginediting:

它也在向上移动?您是否能够解决问题?这不起作用。我可以在SearchBar ShouldBeginediting中将框架的x原点设置为0,但当搜索栏需要位于按钮右侧时(在上面的屏幕截图中),它将成为屏幕的全宽。我似乎也不能改变搜索栏的高度。