Ios 如果在不可见的情况下旋转,UISearchController的搜索栏将被分离并与TableView重叠
所以我有一个带UISearchController的UITableView。它加载良好,然后我进行搜索并选择结果,将新的视图控制器推送到我的UINavigationController 如果,当新的VC出现在屏幕上时,我旋转我的手机,然后旋转回去,然后再返回…当我回到UITableView时,UISearchBar就不见了。如果要进行故障排除,我隐藏了UINavigationBar,或者查看了视图层次结构,我发现它已上移到导航栏后面并被覆盖 我尝试过各种各样的黑客解决方案,比如在完成加载后移动酒吧的框架,但都没有成功。在这件事上我真的需要帮助,我被难住了。我在谷歌上找到的东西都没有帮助 以下是before、after和view Hierarchy的屏幕截图: 以下是所有与视图相关的代码:Ios 如果在不可见的情况下旋转,UISearchController的搜索栏将被分离并与TableView重叠,ios,objective-c,uitableview,uisearchbar,uisearchcontroller,Ios,Objective C,Uitableview,Uisearchbar,Uisearchcontroller,所以我有一个带UISearchController的UITableView。它加载良好,然后我进行搜索并选择结果,将新的视图控制器推送到我的UINavigationController 如果,当新的VC出现在屏幕上时,我旋转我的手机,然后旋转回去,然后再返回…当我回到UITableView时,UISearchBar就不见了。如果要进行故障排除,我隐藏了UINavigationBar,或者查看了视图层次结构,我发现它已上移到导航栏后面并被覆盖 我尝试过各种各样的黑客解决方案,比如在完成加载后移动酒
- (void)viewDidLoad {
[super viewDidLoad];
if (!self.title)
self.title = @"GLOBAL SEARCH";
self.tableView.backgroundColor = [UIColor whiteColor];
//TESTING
//if I don't have this, the bar detaches from the navigation bar
self.edgesForExtendedLayout = UIRectEdgeAll;
self.extendedLayoutIncludesOpaqueBars = YES;
//test
self.definesPresentationContext = YES;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x,
self.searchController.searchBar.frame.origin.y,
self.searchController.searchBar.frame.size.width,
44.0);
self.searchController.searchBar.backgroundImage = [[UIImage alloc] init];
self.searchController.searchBar.backgroundColor = kConstantBaseColor;
self.searchController.searchBar.barTintColor = kConstantBaseColor;
self.searchController.searchBar.tintColor = kConstantLabelColor;
//set color
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:kConstantLabelColor}];
self.searchController.hidesNavigationBarDuringPresentation = NO;
[self.searchController.searchBar setSearchBarStyle:UISearchBarStyleMinimal];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.tableView.clipsToBounds = NO;
self.tableView.tableHeaderView.clipsToBounds = NO;
self.tableView.tableHeaderView.backgroundColor = kConstantBaseColor;
//put purple block above, in case user scrolls up
CGRect bufferFrame = CGRectMake(self.searchController.searchBar.frame.origin.x,
self.searchController.searchBar.frame.origin.y-300,
self.searchController.searchBar.frame.size.width*2,
300);
UIView *purpleBuffer = [[UIView alloc] initWithFrame:bufferFrame];
purpleBuffer.backgroundColor = kConstantBaseColor;
[self.tableView addSubview:purpleBuffer];
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
}];
}
有人有什么解决办法吗?我被难住了,好几天来我一直在用头撞它。非常感谢。我在这里描述一个解决方案:我在这里描述一个解决方案: