问题描述
我需要使用自动版式将UIView
固定在UINavigationBar
(由拥有)下方.
I need to pin a UIView
just below the UINavigationBar
(owned by UINavigationController
) using Autolayout.
这里棘手的事情是UIView
必须是UIApplication
主UIWindow
的子视图.
The tricky thing here is that the UIView
needs to be a subview of the UIApplication
's main UIWindow
.
插入的视图需要跟踪导航栏的位置,例如,如果iOS状态栏增长到两倍的高度(例如,在绿色的返回通话"场景中),或者像横向视图一样更改高度.
The inserted view needs to track the position of the navigation bar, for example if the iOS status bar grows to double height (e.g. in the green "Return to call" scenario), or changes height as in landscape view.
该解决方案还需要与未将视图控制器的edgesForExtendedLayout
设置为无"的透明UINavigationBar
一起使用.
The solution also needs to work with transparent UINavigationBar
s where the view controller's edgesForExtendedLayout
are not set to None.
推荐答案
您尝试按照这本Ray Wanderlich的教程(布局指南部分)?
您应该能够实现所需的结果-不必计算navBar的高度-像这样:
You should be able to achieve the desired outcome - and not have to compute the navBar height - with something like this:
let views = ["myView": myView, "topLayoutGuide":topLayoutGuide]
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[topLayoutGuide]-[myView(30)]",
options: [],
metrics: nil,
views: views)
这篇关于使用自动布局将UIView固定在UINavigationBar下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!