UISearchController放入UINavigationItem时出现故障-iOS 11 +

问题描述 投票:1回答:1

我在FirstViewController的navigationItem中有一个UISearchController。同样在SecondViewController中,我从FirstViewController推送SecondViewController。

当用户滑动返回时,可以看到下面的UI故障。

UISearchController glitch while sliding back

包含UISearchController的区域变暗。如果用户返回到FirstViewController,它看起来不错。但是,如果用户在稍微滑动后仍停留在SecondViewController中,则外观将是这样。

Missing UISearchController in navigationItem

具有searchController的空间现在为空。如果用户向上或向下滚动,则searchController再次变为可见。

选项试图解决问题

  • 使用UITableViewController而不是带有UITableView的UIViewController
  • 切换viewDidLoad和viewWillAppear中的navigationItem.hidesSearchBarWhenScrolling属性>
  • 将navigationItem.searchController设置为viewWillDisappear中的nil
  • 除了这个问题,当我在UIViewController中使用UITableView时,searchController会隐藏在标题下,并且以比Messages,Mail等本机应用程序快的速度显示出来。而且当我使用UITableViewController时,动画是平滑的,但是如果用户没有完全向上或向下滑动,则searchController将被中途击中,如下所示。无论是否有大标题,都会发生这种情况。

UISearchController getting struck

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

更新:在SecondViewController中将extendedLayoutIncludesOpaqueBars设置为true确实解决了该问题。但是,如果用户滑动回去但随后改变了主意,则表视图中会出现一些不想要的东西。

enter image description here

我在FirstViewController的navigationItem中有一个UISearchController。同样在SecondViewController中,我从FirstViewController推送SecondViewController。当用户滑动后退时,...

ios swift uinavigationcontroller uikit uisearchcontroller
1个回答
0
投票

[请尝试一下。。它对我有用。我希望它也对您有用。

© www.soinside.com 2019 - 2024. All rights reserved.