【问题标题】:iOS 11.0 push view controller problem with navigationItem.searchControlleriOS 11.0 推送视图控制器与 navigationItem.searchController 的问题
【发布时间】:2019-02-16 03:41:17
【问题描述】:

我尝试用 searchBar 显示推送子视图控制器,动画期间出现闪烁的灰色条(见图 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)
}

【问题讨论】:

  • 你试过将 pushViewController 动画设置为 false 吗?
  • 不,因为我需要这个动画。

标签: ios swift uisearchbar ios11 uisearchcontroller


【解决方案1】:

如果您尝试push 相同 ViewController() 嵌入了NavigationController,那么您看到的那个栏可能是您的ViewController()navigationBar

尝试新建一个controller,然后push看看bar是否还存在,像这样:

class NewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .red
    }
}

然后在你的 ViewController 的didSelectRowAt 中,推送NewController,像这样:

let newVC = NewController()
navigationController?.pushViewController(newVC, animated: true)

【讨论】:

  • 我还没试过,不知道这样会不会失去navigationBar的模糊效果?
  • @Leo 是的...但我觉得将表格视图或视图的背景设置为白色可以解决问题。
  • 不行,我试过了,两段代码都没有解决问题。
  • @Leo 是你的第一个 VC,tableview 控制器叫ViewController?
  • 两者都是。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多