简体   繁体   English

UISearchController 的 UISearchBar 在 UITableView 滚动时移动错误并跳转

[英]UISearchController's UISearchBar shifts incorrectly and jumps when UITableView is scrolled

In the video, it's a little difficult to see what's going on, so I'll try to explain it.在视频中,很难看到发生了什么,所以我会尝试解释它。 https://youtu.be/yOrCJB9yZlg https://youtu.be/yOrCJB9yZlg

I have UIViewController with UITableView inside its root view.我在其根视图中有UIViewControllerUITableView Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).通过自动Autolayout (绑定方式没有区别:到 SuperView 或到 SafeArea)。

SearchBar added like this: let search = UISearchController(searchResultsController: nil) self.navigationItem.searchController = search SearchBar 添加如下: let search = UISearchController(searchResultsController: nil) self.navigationItem.searchController = search

When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast.当我慢慢滚动表格时,大导航栏和紧凑导航栏之间的过渡,然后显示进出searchBar的动画太快了。 Searchbar jumping in/out of navbar instead of smoothly opened/closed;搜索栏跳入/跳出导航栏,而不是顺利打开/关闭; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).导航栏过渡在两种状态之间跳跃,大而紧凑,当您在屏幕上缓慢移动手指时,不会顺利通过中间的半开状态,就像在系统应用程序(邮件、电话、消息、联系人等)中一样。

I made the example from an empty project to demonstrate the issue;我从一个空项目中制作了这个例子来演示这个问题; there isn't any changes to navigation bar logic, or any logic at all.导航栏逻辑没有任何变化,或者根本没有任何逻辑。 Just two new VC's and this odd behaviour.只是两个新的 VC 和这种奇怪的行为。

If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly.如果我创建 xCode 的“Master-Details”项目示例并将UISearchController添加到其中,它将正常工作。 I assume its because they used UITableViewController instead of UIViewController + UITableView inside.我认为这是因为他们在里面使用了UITableViewController而不是UIViewController + UITableView

What the reason of this behaviour and how to fix it?这种行为的原因是什么以及如何解决?

What you have done is correct.你所做的是正确的。 Did you try running your code in a device?您是否尝试在设备中运行您的代码? Feels more like a glitch in the simulator.感觉更像是模拟器中的小故障。 I tried what you tried and it works fine for me in the device.我尝试了您尝试的方法,并且在设备中对我来说效果很好。 Whereas the glitch occurs in simulator.而故障发生在模拟器中。

Refer to this article .参考这篇文章 They have explained step by step process.他们已经解释了一步一步的过程。

This is a known problem and your code seems fine.这是一个已知问题,您的代码看起来不错。 This problem was already discussed here .这个问题已经在这里讨论

Problem appears when you're using UIScrollView or its subclasses with large navigation titles.当您使用带有大导航标题的UIScrollView或其子类时会出现问题。 It doesn't work.它不起作用。 Problem disappears when you use UICollectionViewController or UITableViewController instead.当您改用UICollectionViewControllerUITableViewController时,问题就会消失。

I had the same problem with the search controller transition and tableview.我在搜索控制器转换和 tableview 上遇到了同样的问题。 like this its flickering or tableview was jumping.像这样它的闪烁或 tableview 正在跳跃。 The search controller was on the navigation item.搜索控制器位于导航项上。

The key solution is to remove safe area guide from your view controller and assign top bottom left right constraints to your tableview.关键的解决方案是从您的视图控制器中删除安全区域指南,并为您的 tableview 分配左上右下约束。 It will be smooth like this像这样顺利

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

相关问题 激活和停用UISearchController时,UITableView在位置之间跳转 - UITableView jumps between positions when activating and deactivating UISearchController 滚动时,UITableView崩溃 - UITableView crashes when it's scrolled 粘贴到UISearchController的UISearchBar时启用返回键 - Enable Return Key when Pasting into a UISearchController's UISearchBar UISearchController与UIBarPositionTopAttached将UISearchBar抛出屏幕; 不可能有UITableView的标准UISearchController? - UISearchController with UIBarPositionTopAttached throws UISearchBar offscreen; impossible to have standard UISearchController with UITableView? 当UISearchController的searchBar处于活动状态时,点击UITableView索引(A…Z) - Tap on a UITableView Index (A…Z) when a UISearchController's searchBar is active UISearchController的UISearchBar不扩展到状态栏 - UISearchController's UISearchBar not extending to status bar 轻按时,UISearchController中的UISearchBar向右滑动 - UISearchBar in UISearchController slips to the right when tapped 活动时 UISearchController 的 UISearchBar 移出屏幕 - UISearchBar of UISearchController moves off screen when active 在UISearchBar上键入时为什么UISearchController会消失? - Why UISearchController disappears when typing on UISearchBar? UISearchController 在关闭时清除 UISearchBar 文本 - UISearchController clears UISearchBar text when dismissed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM