Open Davisjy opened 7 years ago
same problem
@ETHANAIR 我这边最新版没问题。 加我QQ:499491531 备注:#122
@iphone5solo 最新版已经OK了
// Adapt the search bar layout problem in the navigation bar on iOS 11 // More details : https://github.com/iphone5solo/PYSearch/issues/108 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0) { // iOS 11 ============添加下面这部分代码,定义titleView位置,=============== UIView titleView = self.navigationItem.titleView; titleView.py_x = PYSEARCH_MARGIN 1.5; titleView.py_y = self.view.py_width > self.view.py_height ? 3 : 7; titleView.py_width = self.view.py_width - cancelButton.py_width - titleView.py_x 2 - 3; titleView.py_height = self.view.py_width > self.view.py_height ? 24 : 30; ============添加上面这部分代码,定义titleView位置,=============== UINavigationBar navBar = self.navigationController.navigationBar; navBar.layoutMargins = UIEdgeInsetsZero; CGFloat space = 8; for (UIView *subview in navBar.subviews) { if ([NSStringFromClass(subview.class) containsString:@"ContentView"]) { subview.layoutMargins = UIEdgeInsetsMake(0, space, 0, space); // Fix cancel button width is modified break; } }
_searchBar.py_width = self.view.py_width - cancelButton.py_width - PYSEARCH_MARGIN * 3 - 8;
_searchBar.py_height = self.view.py_width > self.view.py_height ? 24 : 30;
_searchTextField.frame = _searchBar.bounds;
} else {
UIView *titleView = self.navigationItem.titleView;
titleView.py_x = PYSEARCH_MARGIN * 1.5;
titleView.py_y = self.view.py_width > self.view.py_height ? 3 : 7;
titleView.py_width = self.view.py_width - cancelButton.py_width - titleView.py_x * 2 - 3;
titleView.py_height = self.view.py_width > self.view.py_height ? 24 : 30;
}
========== 这个地方删掉
//viewWillAppear要这样写
// // Adjust the view according to the navigationBar.translucent
// if (NO == self.navigationController.navigationBar.translucent) {
// self.baseSearchTableView.contentInset = UIEdgeInsetsMake(0, 0, self.view.py_y, 0);
// self.searchSuggestionVC.view.frame = CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame) - self.view.py_y, self.view.py_width, self.view.py_height + self.view.py_y);
// if (!self.navigationController.navigationBar.barTintColor) {
// self.navigationController.navigationBar.barTintColor = PYSEARCH_COLOR(249, 249, 249);
// }
// }
if (self.currentOrientation != [[UIDevice currentDevice] orientation]) { // orientation changed, reload layout
self.hotSearches = self.hotSearches;
self.searchHistories = self.searchHistories;
self.currentOrientation = [[UIDevice currentDevice] orientation];
}
UIButton *cancelButton = self.navigationItem.rightBarButtonItem.customView;
CGFloat buttonWidth = cancelButton.py_width;
CGFloat buttonHeight = cancelButton.py_height;
[cancelButton sizeToFit];
if (buttonWidth >= cancelButton.py_width) {
cancelButton.py_width = buttonWidth;
cancelButton.py_width += 5;
}
if (buttonHeight >= cancelButton.py_height) {
cancelButton.py_height = buttonHeight;
}
// Adapt the search bar layout problem in the navigation bar on iOS 11
// More details : iphone5solo#108
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0) { // iOS 11
//============添加下面这部分代码,定义titleView位置,===============
UIView *titleView = self.navigationItem.titleView;
titleView.py_x = PYSEARCH_MARGIN * 1.5;
titleView.py_y = self.view.py_width > self.view.py_height ? 3 : 7;
titleView.py_width = self.view.py_width - cancelButton.py_width - titleView.py_x * 2 - 3;
titleView.py_height = self.view.py_width > self.view.py_height ? 24 : 30;
//============添加上面这部分代码,定义titleView位置,===============
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.layoutMargins = UIEdgeInsetsZero;
CGFloat space = 8;
for (UIView *subview in navBar.subviews) {
if ([NSStringFromClass(subview.class) containsString:@"ContentView"]) {
subview.layoutMargins = UIEdgeInsetsMake(0, space, 0, space); // Fix cancel button width is modified
break;
}
}
_searchBar.py_width = self.view.py_width - cancelButton.py_width - PYSEARCH_MARGIN * 3 - 8;
_searchBar.py_height = self.view.py_width > self.view.py_height ? 24 : 30;
_searchTextField.frame = _searchBar.bounds;
} else {
UIView *titleView = self.navigationItem.titleView;
titleView.py_x = PYSEARCH_MARGIN * 1.5;
titleView.py_y = self.view.py_width > self.view.py_height ? 3 : 7;
titleView.py_width = self.view.py_width - cancelButton.py_width - titleView.py_x * 2 - 3;
titleView.py_height = self.view.py_width > self.view.py_height ? 24 : 30;
}
}
iOS 11.2 正常了,搞了两个小时!!!!!!!!!!!!!!!!!!!!!!!!!
不建议使用[[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0
做判断.
@available(iOS 11.0, *)
这个就很好
不知道是不是我的问题