【问题标题】:UISearchController glitches when placed in UINavigationItem - iOS 11+放置在 UINavigationItem 中时 UISearchController 出现故障 - iOS 11+
【发布时间】:2020-02-24 16:03:50
【问题描述】:

我在FirstViewControllernavigationItem 中有一个UISearchController。在SecondViewController 中也是如此,我从FirstViewController 推送SecondViewController

当用户滑动返回时,下面的 UI 故障是可见的。

包含UISearchController 的区域变暗。如果用户返回FirstViewController,它看起来不错。但是如果用户在滑动一点之后停留在SecondViewController,那么就是这个样子了。

拥有searchController 的空间现在是空的。如果用户向上或向下滚动,searchController 将再次可见。

选项试图解决问题

  • 使用UITableViewController 代替UIViewControllerUITableView
  • viewDidLoadviewWillAppear 中切换navigationItem.hidesSearchBarWhenScrolling 属性
  • viewWillDisappear 中将navigationItem.searchController 设置为nil

除了这个问题,当我在UIViewController 中使用UITableView 时,searchController 隐藏在标题下方,并且比消息、邮件等本机应用程序的输出速度略高。 当我使用UITableViewController 时,动画很流畅,但如果用户没有完全向上或向下滑动,则 searchController 会被击中,如下所示。无论有没有大标题,都会发生这种情况。

我的用例也可以实现,如果有人可以回答this question

更新: 在SecondViewController 中将extendedLayoutIncludesOpaqueBars 设置为true 确实解决了这个问题。但是如果用户滑动返回但随后改变了他/她的想法,那么 tableview 中会有一个轻微的不受欢迎的混蛋。

【问题讨论】:

    标签: ios swift uinavigationcontroller uikit uisearchcontroller


    【解决方案1】:

    请试试这个。它对我有用。我希望它也对你有用。

    Objective-C

    -(void)viewWillDisappear:(BOOL)animated{
        if (@available(iOS 13.0, *)) {
            [self.navigationController.view setNeedsLayout]; 
            [self.navigationController.view layoutIfNeeded];
        }
    }
    

    斯威夫特

    func viewWillDisappear(_ animated: Bool) {
        if (@available(iOS 13.0, *)) {
             self.navigationController?.view.setNeedsLayout()     
             self.navigationController?.view.layoutIfNeeded()
        }
    }
    

    如果它不起作用,则在您推送或呈现 ViewController 时将动画设置为 NO 或 false

    【讨论】:

    • 这在一定程度上有效,但并不完全。发生毛刺的间距变小了,但仍然略微可见。而且,将动画设置为 false 甚至在我们的应用中都不是一个选项,这会导致用户体验不一致。
    猜你喜欢
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    相关资源
    最近更新 更多