UISearchController-黑色矩形

时间:2018-12-30 17:25:17

标签: swift cocoa navigation tableview ios11

我正在使用UISearchcontroller实现一个简单的tableViewController。

问题在于,每当我按下搜索字段时,键盘显示后就会立即出现一个黑色矩形。

我也尝试使用definePresentationContext和searchBarStyle,但是它一直显示矩形。另一方面,由于没有键盘,因此在模拟器中似乎没有发生。

更新:在一些照片下面。

ViewController:

class ListGlobalViewController: UITableViewController, StoryboardSceneBased, ViewModelBased {

  static var sceneStoryboard: UIStoryboard = UIStoryboard(name: "DataSelectorViewController", bundle: Bundle.main)

  // --------------------
  // MARK: - Properties
  // --------------------
  var viewModel: ListGlobalViewModel!
  private let disposeBag = DisposeBag()


  private let searchController: UISearchController = {
    let searchController = UISearchController(searchResultsController: nil)
    searchController.searchBar.searchBarStyle = .minimal
    searchController.dimsBackgroundDuringPresentation = false
    searchController.hidesNavigationBarDuringPresentation = true
    return searchController
  }()

  override func viewDidLoad() {
    super.viewDidLoad()
    tableView.tableFooterView = UIView()
    configure(with: viewModel)

    navigationItem.largeTitleDisplayMode = .automatic
    navigationItem.searchController = searchController
    navigationItem.hidesSearchBarWhenScrolling = false
  }

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
  }

  override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    self.searchController.isActive = false
  }
  override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
  }

  // --------------------
  // MARK: - Functions
  // --------------------
  func configure(with viewModel: ListGlobalViewModel) {
    self.tableView.delegate = nil
    self.tableView.dataSource = nil

    viewModel.outputs.listDataObservable.bind(to: self.tableView.rx.items(cellIdentifier: "listGlobalCell", cellType: ListGlobalCell.self)) { (index, model, cell) in
       cell.model = model
    }.disposed(by: disposeBag)

    searchController.searchBar.rx.text.filterNil().throttle(1, scheduler: MainScheduler.instance).distinctUntilChanged().subscribe(viewModel.inputs.searchBarObservable).disposed(by: disposeBag)

  }
}

导航默认值:

let controller = UINavigationController()
    controller.navigationBar.isTranslucent = false
    controller.navigationBar.prefersLargeTitles = true
    controller.definesPresentationContext = true
    controller.navigationBar.titleTextAttributes = [ NSAttributedString.Key.font: UIFont.bold(size: 24), NSAttributedString.Key.foregroundColor: UIColor.black ]

    if #available(iOS 11, *) {
      controller.navigationBar.largeTitleTextAttributes = [ NSAttributedString.Key.font: UIFont.bold(size: 33), NSAttributedString.Key.foregroundColor: UIColor.black ]
    }
    return controller

图片: Normal State

坚固 Bugged state

1 个答案:

答案 0 :(得分:0)

如果使用UITextField,请改用UISearchBar。您可以为uitextfield提供任何设计。 UISearch栏具有有限的可设计属性。您也可以使用文本框访问任何搜索功能。