iOS的11自定义导航栏给出了两个酒吧
问题描述:
当我尝试定制UINavigationBar的添加到视图控制器这样iOS的11自定义导航栏给出了两个酒吧
class ViewController: UIViewController
{
static let nav_bar_height: CGFloat = 64
let nav_bar: UINavigationBar =
{
let nav_bar = UINavigationBar()
nav_bar.translatesAutoresizingMaskIntoConstraints = false
nav_bar.backgroundColor = .blue
return nav_bar
}()
override func viewDidLoad()
{
super.viewDidLoad()
view.backgroundColor = .yellow
view.addSubview(nav_bar)
nav_bar.heightAnchor.constraint(equalToConstant: ViewController.nav_bar_height).isActive = true
nav_bar.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
nav_bar.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
nav_bar.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width).isActive = true
}
}
任何想法,为什么有一个较小的高度白色的酒吧?
这是AppDelegate中
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let vc = ViewController()
window?.rootViewController = vc
// Override point for customization after application launch.
return true
}...
答
您在导航界面可能是用一个UINavigationController为您的视图控制器的父。
所以第二个导航栏是UINavigationController的导航栏。
此外,您定位和调整导航栏的方式并不是您如何做到的。但是我们可以在完成与周围的导航控制器界面的拼搏之后处理这个问题。 – matt
但没有导航控制器界面。 'class AppDelegate:UIResponder,UIApplicationDelegate {0} {0} {0}} var window:UIWindow? FUNC应用(_应用:UIApplication的,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:任何]) - >布尔{ 窗口=一个UIWindow?(帧:UIScreen.main.bounds) 窗口.makeKeyAndVisible() 设VC =的ViewController () window?.rootViewController = vc //覆盖应用程序启动后自定义的点。 return true } ' –
所以你声称。但我敢打赌,你正在隐瞒的东西。我认为你有一个你没有告诉我们的故事板,我认为故事板中的初始视图控制器是一个导航控制器(使用ViewController作为其根视图控制器),_that_是正在加载的视图控制器。第二个导航栏仅仅是对这个问题的诊断。 – matt