我需要将 navController 的 navBar 的 barPosition 更改为 topAttached 类型。我尝试使用UINavigationBarDelegate 的position(for bar:)方法。在 MyViewController 类中:
navigationController?.navigationBar.delegate = self
Run Code Online (Sandbox Code Playgroud)
并延伸:
extension MyViewController: UINavigationBarDelegate{
func position(for bar: UIBarPositioning) -> UIBarPosition {
return .topAttached
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在控制器管理的 UINavigationBar 上手动设置委托。”
那么还有其他方法可以改变 swift 3 中的 barPosition 吗?提前致谢!