簡體   English   中英

iOS 11自定義導航欄提供兩個欄

[英]iOS 11 custom navigation bar gives two bars

當我嘗試向這樣的視圖控制器添加自定義UINavigationBar時

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的導航欄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM