简体   繁体   中英

UISearchBar in UISearchController slips to the right when tapped

I have a UISearchBar inside a UISearchController which pushes to the right when tapped.

This is how the search bar looks after the initial setup 点击前搜索

Below is the code which i use to setup the search bar inside the UIViewController

 //Set self object to recieve all the updates of UISearchResultsController
self.searchResultsUpdater = self;


//Hide navigation bar during presentation of the UISearchController.
self.hidesNavigationBarDuringPresentation = YES;

//set delegates to UISearchBar and UISearchController
self.delegate = self;
self.searchBar.delegate = self;

//Set scope bars that does not exist
self.searchBar.scopeButtonTitles = [NSArray array];

//Some additional settings that can be configured

self.context.definesPresentationContext = YES;
self.dimsBackgroundDuringPresentation = NO;

[self.searchBar sizeToFit];

self.tableView.tableHeaderView = self.searchBar;

self.context.edgesForExtendedLayout = UIRectEdgeTop;
self.searchBar.clipsToBounds = YES;

Once the user presses on the search bar, it behaves like this. 点击搜索栏后,它会向右推

All of the other controllers are working, fine. It's just one controller which keeps acting in a weird way.

The application supports both iPhone and iPad, the search seems to be working fine on the iPhone but on the iPad it behaves mysteriously.

I was able to fix the issue by my self. What i had to do was:

self.definesPresentationContext = false;

and to remove it once the view is dismissed

self.searchController.active = false;

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