简体   繁体   English

iOS 11搜索栏动画bug

[英]iOS 11 search bar animation bug

I have a search controller attached to a navigation item with a customized search bar styling (colors). 我有一个搜索控制器附加到导航项目与自定义搜索栏样式(颜色)。 Here is the code: 这是代码:

    searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.dimsBackgroundDuringPresentation = false

    let bar = searchController.searchBar
    bar.placeholder = "Search songs"
    bar.backgroundImage = .transparentPixel // transparent UIImage of size 1x1
    bar.backgroundColor = UIColor(red: 0.02, green: 0.04, blue: 0.06, alpha: 1)
    bar.tintColor = .white
    bar.barTintColor = UIColor(red: 0.02, green: 0.04, blue: 0.06, alpha: 1)
    bar.isTranslucent = false
    bar.barStyle = .default
    bar.showsCancelButton = true

    definesPresentationContext = true

and then I add it to the controller: 然后我将它添加到控制器:

    if #available(iOS 11.0, *) {
        controller.navigationItem.searchController = searchController
        controller.navigationItem.hidesSearchBarWhenScrolling = false
    } else {
        // Fallback on earlier versions
        tableView.tableHeaderView = searchController.searchBar
    }

When I navigate to that controller for a small amount of time during the animation the search bar displays white color instead of the ones I set up. 当我在动画期间导航到该控制器一小段时间时,搜索栏显示白色而不是我设置的颜色。 Not sure if those are default styling or just one white background color. 不确定这些是默认样式还是仅一种白色背景颜色。 Here is the video: 这是视频:

在此输入图像描述

During debugging the view hierarchy I found a white background, not sure if it has anything to do with the problem: 在调试视图层次结构期间,我发现了一个白色背景,不确定它是否与问题有关:

在此输入图像描述 在此输入图像描述


UPDATE: The official Apple sample code for searching (can be found here ) has similar problem. 更新:用于搜索的官方Apple示例代码(可在此处找到)具有类似的问题。 In addition it displays black area below search bar while animating a push of a new controller. 此外,它会在搜索栏下方显示黑色区域,同时设置推送新控制器的动画。 I have changed the background color of the window to red and saw red color instead: 我已将窗口的背景颜色更改为红色并改为显示红色:

在此输入图像描述

In my case I have no window or views with white background. 在我的情况下,我没有白色背景的窗口或视图。 Would be interesting to understand if anyone had this problem and how to solve it. 如果有人遇到这个问题以及如何解决它会很有趣。

我通过删除背景图像设置修复了相同的错误

navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)

Try this. 尝试这个。

self.extendedLayoutIncludesOpaqueBars = YES;

I found this solution below. 我在下面找到了解决方案。

iOS 11 UIRefreshControl with NavigationBar LargeTitle and SearchController disappearing 带有NavigationBar LargeTitle和SearchController的iOS 11 UIRefreshControl消失了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM