使用自动布局将UIView固定在UINavigationBar下方 [英] Pin UIView just below UINavigationBar using Autolayout

查看:137
本文介绍了使用自动布局将UIView固定在UINavigationBar下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用自动版式将UIView固定在UINavigationBar(由拥有)下方.

I need to pin a UIView just below the UINavigationBar (owned by UINavigationController) using Autolayout.

这里棘手的事情是UIView必须是UIApplicationUIWindow的子视图.

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 UINavigationBars where the view controller's edgesForExtendedLayout are not set to None.

推荐答案

您尝试按照您应该能够实现所需的结果-不必计算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下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆