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的目標?請不要暗示將子控制器的下半部分設置爲空白等等。
你如何設置'navController.topViewController?.view.heightAnchor'? – DonMag
這是孩子的意見決定其高度。 – GoldenJoe
所以...你的導航控制器的根視圖控制器有一個'.height'約束的子視圖?在哪裏/如何設置高度限制? – DonMag