ko1o / PYSearch

🔍 An elegant search controller which replaces the UISearchController for iOS (iPhone & iPad) .

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

搜索结果布局有问题

zhaohuang2016 opened this issue · comments

搜索结果超过一屏时,键盘收起状态时,非刘海屏手机最后一个cell有半个cell的高度显示不了,刘海屏手机差不多有一个cell显示不了,demo多加点假数据就能重现
for (int i = 0; i < arc4random_uniform(5) + 30; i++) {
NSString *searchSuggestion = [NSString stringWithFormat:@"Search suggestion %d", i];
[searchSuggestionsM addObject:searchSuggestion];
}

等了几天,作者没回复,所以自己改了,希望能帮到遇到我同样问题的人,我的情况是搜索结果显示的cell是自定义的把源代码替换了,所以布局有问题,如果有同样情况的人可以参考下我的解决代码:
PYSearchSuggestionViewController类的这个方法

  • (void)setSearchSuggestions:(NSArray<NSString *> *)searchSuggestions
    {
    _searchSuggestions = [searchSuggestions copy];

    [self.tableView reloadData];

    /**

    • Adjust the searchSugesstionView when the keyboard changes.
    • more information can see : #61
      */
      if (self.keyboardDidShow && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardShow, UIEdgeInsetsZero) && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardShow, UIEdgeInsetsMake(-30, 0, 30 - CGRectGetMaxY(self.navigationController.navigationBar.frame), 0))) {
      self.tableView.contentInset = self.originalContentInsetWhenKeyboardShow;
      } else if (!self.keyboardDidShow && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardHidden, UIEdgeInsetsZero) && !UIEdgeInsetsEqualToEdgeInsets(self.originalContentInsetWhenKeyboardHidden, UIEdgeInsetsMake(-30, 0, 30 - CGRectGetMaxY(self.navigationController.navigationBar.frame), 0))) {
      self.tableView.contentInset = self.originalContentInsetWhenKeyboardHidden;
      }
      self.tableView.contentOffset = CGPointMake(0, -self.tableView.contentInset.top);

    if (@available(iOS 11.0, *))
    {
    UIEdgeInsets contentInsets = self.tableView.adjustedContentInset;
    if (self.keyboardDidShow) {

          self.tableView.contentInset = UIEdgeInsetsMake(-30, 0,-30, 0);
      } else {
          
          CGFloat bottom = isIphoneX == YES ? [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom + contentInsets.bottom : contentInsets.bottom;
          self.tableView.contentInset = UIEdgeInsetsMake(-30,0,bottom, 0);
      }
    

    }
    }
    把源代码的最后一行替换成
    if (@available(iOS 11.0, *))
    {
    UIEdgeInsets contentInsets = self.tableView.adjustedContentInset;
    if (self.keyboardDidShow) {

          self.tableView.contentInset = UIEdgeInsetsMake(-30, 0,-30, 0);
      } else {
          
          CGFloat bottom = isIphoneX == YES ? [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom + contentInsets.bottom : contentInsets.bottom;
          self.tableView.contentInset = UIEdgeInsetsMake(-30,0,bottom, 0);
      }
    

    }