iOS 11.0使用navigationItem.searchController推送视图控制器问题

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

我尝试用搜索栏显示推动子视图控制器,在动画期间出现闪烁的灰色条(参见图2),我该如何修复该动画?谢谢。

码:

override func viewDidLoad() {
  super.viewDidLoad()

  if title == nil {
    title = "Title"
  }

  if #available(iOS 11.0, *) {
    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.searchController = searchController
  }

  definesPresentationContext = true
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  tableView.deselectRow(at: indexPath, animated: true)


  let vc = ViewController()
  vc.hidesBottomBarWhenPushed = true
  navigationController?.pushViewController(vc, animated: true)
}

step1 step2 step3

ios swift uisearchbar ios11 uisearchcontroller
1个回答
0
投票

如果你试图pushViewController()嵌入相同的NavigationController,你看到的那个酒吧可能是你的navigationBarViewController()

尝试创建一个新的控制器,然后push查看该栏是否仍然存在,如下所示:

class NewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .red
    }
}

然后在你的ViewController的didSelectRowAt中,推送NewController,如下所示:

let newVC = NewController()
navigationController?.pushViewController(newVC, animated: true)
© www.soinside.com 2019 - 2024. All rights reserved.