在我的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;
}
答案 0 :(得分:0)
您可以尝试使用positionAdjustmentForSearchBarIcon:
或setPositionAdjustment:forSearchBarIcon:
邮件调用委托调用中的搜索栏:searchBarTextDidBeginEditing: