0

我在計算UINavigationController的實際結構時遇到了一些麻煩。我想約束它,以便它的視圖匹配頂層控制器視圖的首選大小。將UINavigationView的大小限制爲其當前呈現的控制器的大小?

喜歡的東西:

navController.view.heightAnchor.constraint(equalTo: navController.topViewController?.view.heightAnchor).isActive = true 

給我的錯誤:

*** Terminating app due to uncaught exception 'NSGenericException', 
reason: 'Unable to activate constraint with anchors 
<NSLayoutYAxisAnchor:0x600000472e00 "UILayoutContainerView:0x7f9f01d14310.top"> 
and <NSLayoutYAxisAnchor:0x608000270ac0 "UIView:0x7f9f01d182b0.top"> 
because they have no common ancestor. Does the constraint or its anchors 
reference items in different view hierarchies? That's illegal.' 

顯然頂部控制器的觀點是在不同的層次。這怎麼可能?我如何實現創建非全屏UINavigationController的目標?請不要暗示將子控制器的下半部分設置爲空白等等。

+0

你如何設置'navController.topViewController?.view.heightAnchor'? – DonMag

+0

這是孩子的意見決定其高度。 – GoldenJoe

+0

所以...你的導航控制器的根視圖控制器有一個'.height'約束的子視圖?在哪裏/如何設置高度限制? – DonMag

回答

0

How can I achieve my goal of creating a non-full screen UINavigationController?

兩種簡單的方法:

  • 目前導航控制器作爲呈現視圖控制器和自定義演示。 (A酥料餅的是一個例子,通過該方式:導航控制器調整自身到其子的優選尺寸。)

  • 使一個父視圖控制器,使導航控制器及其子。

在這兩種方法中,導航控制器的視圖大小完全取決於您。