简体   繁体   English

带有大标题的 UISearchController,UI 在关闭时行为不端

[英]UISearchController with Large titles, UI misbehave on dismissing

I have a UITableViewController which has a UISearchController in the navigation bar.我有一个 UITableViewController,它在导航栏中有一个 UISearchController。

When I tap the search, pull down once and then press cancel, I see a weird UI behavior.当我点击搜索,下拉一次然后按取消时,我看到了一个奇怪的 UI 行为。

搜索控制器

I can't find any particular reasons why this happens.我找不到发生这种情况的任何具体原因。 This issue is not reproduced every time.这个问题不是每次都重现。 It happens more often when the navigation bar has some buttons, as you can see in the GIF above.当导航栏有一些按钮时,它会更频繁地发生,正如您在上面的 GIF 中看到的那样。

When I go back to the first view controller (which does not have any navigation bar buttons) and repeat same steps, the issue is reproduced on rare occasions.当我 go 回到第一个视图 controller (没有任何导航栏按钮)并重复相同的步骤时,该问题在极少数情况下会重现。

This issue happens only when you pull down in the ViewController which has the search controller.仅当您在具有搜索 controller 的 ViewController 中下拉时才会出现此问题。 If you are using a results controller and pull down in the results controller, this issue is not reproduced.如果您使用结果 controller 并下拉结果 controller,则不会重现此问题。

Below is the code used in the sample app.下面是示例应用程序中使用的代码。

import UIKit

class SearchViewController: UITableViewController {

    lazy var resultsController = ResultsVC()
    lazy var searchController = UISearchController(searchResultsController: resultsController)

    override func viewDidLoad() {
        super.viewDidLoad()

        configureSearchController()

        navigationItem.largeTitleDisplayMode = .always
        navigationController?.navigationBar.prefersLargeTitles = true
        navigationItem.title = "Search VC"
    }

    func configureSearchController() {
        navigationItem.searchController = searchController
        navigationItem.hidesSearchBarWhenScrolling = true
        searchController.obscuresBackgroundDuringPresentation = false
        searchController.hidesNavigationBarDuringPresentation = true
        searchController.searchResultsUpdater = resultsController
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        navigationController?.pushViewController(SearchViewController(), animated: true)
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 50
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel?.text = "Searchable cell"
        return cell
    }
}

class ResultsVC: UITableViewController {

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 50
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel?.text = "Result cell"
        return cell
    }
}

extension ResultsVC: UISearchResultsUpdating {
    func updateSearchResults(for searchController: UISearchController) {
        print(searchController.searchBar.text)
    }
}

I tried to change the tableView's content offset using tableView.setContentOffet in UISearchControllerDelegate methods willPresentSearchController and willDismissSearchController but the y position varies for each device, and it cannot be a universal fix.我尝试使用 UISearchControllerDelegate 方法willPresentSearchControllerwillDismissSearchController中的tableView.setContentOffet更改 tableView 的内容偏移量,但 y position 因每个设备而异,它不能是通用修复。

PS: This issue doesn't occur in most simulators. PS:大多数模拟器不会出现这个问题。 So kindly try the same code in your mobile.因此,请在您的手机中尝试相同的代码。

This issue can be prevented from happening by setting这个问题可以通过设置来防止发生

searchController.obscuresBackgroundDuringPresentation = true

This means that user can not scroll the table view after tapping search.这意味着用户在点击搜索后无法滚动表格视图。 However, the user can scroll the results controller after it is presented.但是,用户可以在 controller 出现后滚动结果。

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

相关问题 在大型标题UINavigationBar中删除UISearchController顶部的1px行 - Remove 1px line at top of UISearchController in large titles UINavigationBar UISearchController在解雇它时有奇怪的行为 - UISearchController weird behavior on dismissing it UISearchController在以模态方式解除时发出问题 - UISearchController issues when dismissing modally 具有大标题的UISearchController在选项卡栏中崩溃,“只有一个具有顶部边界边缘的调色板可以在转换之外处于活动状态” - UISearchController with large titles crashes in Tab bar with “Only one palette with a top boundary edge can be active outside of a transition” 取消UISearchController会破坏分组的UITableViewController视觉效果 - Dismissing UISearchController breaks grouped UITableViewController visual 在关闭UISearchController时,UINavigationBar涵盖UITableView - UINavigationBar covers UITableView when dismissing UISearchController Swift 5 & iOS 13 UISearchController 错误的呈现和关闭行为 - Swift 5 & iOS 13 UISearchController wrong presenting and dismissing behaviour UISearchController“手动”搜索UI故障 - UISearchController “manual” search UI glitch 滚动滚动大标题的应用程序 - App with Large Titles jittering on scroll 取消位置和通知设置Xcode Ui测试 - Dismissing location and notifcation settings Xcode Ui testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM