PYSearch icon indicating copy to clipboard operation
PYSearch copied to clipboard

最新下载的跑在iOS11.0.3上,搜索框偏移右下方

Open Davisjy opened this issue 8 years ago • 7 comments

不知道是不是我的问题

Davisjy avatar Oct 16 '17 10:10 Davisjy

same problem

ETHANAIR avatar Oct 23 '17 01:10 ETHANAIR

@ETHANAIR 我这边最新版没问题。 加我QQ:499491531 备注:#122

ko1o avatar Oct 23 '17 01:10 ko1o

@iphone5solo 最新版已经OK了

ETHANAIR avatar Oct 26 '17 05:10 ETHANAIR

// 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;
}

alkayoun avatar Nov 30 '17 07:11 alkayoun

========== 这个地方删掉

  • (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; }

//viewWillAppear要这样写

  • (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];

// // 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;
}

}

MuZiLee avatar Dec 21 '17 00:12 MuZiLee

iOS 11.2 正常了,搞了两个小时!!!!!!!!!!!!!!!!!!!!!!!!!

MuZiLee avatar Dec 21 '17 00:12 MuZiLee

不建议使用[[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0
做判断.

@available(iOS 11.0, *)

这个就很好

MuZiLee avatar Dec 21 '17 00:12 MuZiLee