Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch iOS 11上的搜索栏与状态栏重叠_Cocoa Touch_Uisearchbar_Ios11 - Fatal编程技术网

Cocoa touch iOS 11上的搜索栏与状态栏重叠

Cocoa touch iOS 11上的搜索栏与状态栏重叠,cocoa-touch,uisearchbar,ios11,Cocoa Touch,Uisearchbar,Ios11,我正在使用UISearchController和UISearchResultsController来实现搜索功能 MySearchResultsController实现UISearchResultsUpdated和UISearchBarDelegate: override open func viewDidLoad() { super.viewDidLoad() self.edgesForExtendedLayout = []; self.automaticallyAdj

我正在使用UISearchController和UISearchResultsController来实现搜索功能

MySearchResultsController实现UISearchResultsUpdated和UISearchBarDelegate:

override open func viewDidLoad() {
    super.viewDidLoad()
    self.edgesForExtendedLayout = [];
    self.automaticallyAdjustsScrollViewInsets = false;
}
我在表格标题中显示搜索栏,如MyTableViewController中所示:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
    self.searchController.searchResultsUpdater = self.searchResultsController;
    self.searchController.searchBar.delegate = self.searchResultsController;
    self.searchController.searchBar.scopeButtonTitles = @[NSLocalizedString(@"SEARCH_SCOPE_TEMPERATURES", nil), NSLocalizedString(@"SEARCH_SCOPE_KNOWHOW", nil)];
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.definesPresentationContext = YES;
}
override open func viewDidLoad() {
    super.viewDidLoad()
    self.automaticallyAdjustsScrollViewInsets = false;
    if (@available(iOS 11.0, *)) {
        //NSLog(@"iOS 11.0");
    } else {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        //NSLog(@"iOS < 11.0");
    }
}
这在以前工作得很好,但在iOS 11下,只要我点击搜索栏,它就会与状态栏重叠(见屏幕截图)。我尝试了很多不同的方法让它正确显示,但还没有找到解决方案


我通过将UISearchController子类化成功地解决了这个问题。我的答案是Swift,但也许原则也适用于ojective-c。请看我的回答:

我发现问题在于演示视图控制器也设置了

override open func viewDidLoad() {
    super.viewDidLoad()
    self.edgesForExtendedLayout = [];
    self.automaticallyAdjustsScrollViewInsets = false;
}
我必须这样做,因为表视图实际上并没有一直延伸到顶部

我在演示视图控制器中这样解决了这个问题:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
    self.searchController.searchResultsUpdater = self.searchResultsController;
    self.searchController.searchBar.delegate = self.searchResultsController;
    self.searchController.searchBar.scopeButtonTitles = @[NSLocalizedString(@"SEARCH_SCOPE_TEMPERATURES", nil), NSLocalizedString(@"SEARCH_SCOPE_KNOWHOW", nil)];
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.definesPresentationContext = YES;
}
override open func viewDidLoad() {
    super.viewDidLoad()
    self.automaticallyAdjustsScrollViewInsets = false;
    if (@available(iOS 11.0, *)) {
        //NSLog(@"iOS 11.0");
    } else {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        //NSLog(@"iOS < 11.0");
    }
}
override open func viewDidLoad(){
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets=false;
如果(@可用(iOS 11.0,*)){
//NSLog(@“iOS 11.0”);
}否则{
self.edgesForExtendedLayout=UIRectEdgeNone;
//NSLog(@“iOS<11.0”);
}
}

这似乎是iOS 11的一个bug,或者至少是一个奇怪的行为…

这就是我的工作原理:

    override func viewDidLoad() {
        // to fix the Status Bar Issue:
        if #available(iOS 11.0, *) {
            definesPresentationContext = true
        }
       // You'll also need this properties on your Search Bar:
        searchController = UISearchController.init(searchResultsController: nil)
        searchController?.searchResultsUpdater = self
        searchController?.hidesNavigationBarDuringPresentation = false
    }

我刚刚发现,当我删除范围按钮标题时(我不想这么做…),这不会发生。非常感谢!searchController?.hidesNavigationBarDuringPresentation就是我要找的!隐藏导航栏可以防止搜索栏优雅的上移动画。这可能会解决重叠问题,因为不再有向上移动的动画,但这可能不是每个人都想要的。我个人喜欢上移动画,但对于iOS 11中的这个bug,这肯定是一个bug,尽管我发现我不必提供答案中给出的if语句,并标记为正确。只需添加赋值语句就可以修复所有发生错误的情况(从8.2到10.3.1的所有版本),并且不会改变显示良好的情况(包括11.0和11.0之后的版本)。