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酥料饼的是一个例子,通过该方式:导航控制器调整自身到其子的优选尺寸。)

  • 使一个父视图控制器,使导航控制器及其子。

在这两种方法中,导航控制器的视图大小完全取决于您。