在状态栏下方获取自动布局
Getting Autolayout beneath the status bar
我已经阅读了 iOS 7 中关于自动布局和状态栏行为的多篇先前帖子,但仍然不知道如何让我的自动布局对象位于状态栏下方。
我目前有
self.automaticallyAdjustsScrollViewInsets = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;
并且搜索栏应用了视觉格式,如 V:|-0-searchBar-|
。
搜索栏呈现在状态栏下方
不出所料。
我一直找不到使搜索栏从状态栏底部边缘开始的解决方案。如何做到这一点?
编辑: 我查看了顶部布局选项,但我的自定义视图控制器有一个 xib。没有可用的顶部布局指南。我如何支持此设置?我想避免检查系统版本。
您需要使用topLayoutGuide
。
Apple 在这个问题上有很好的指南:https://developer.apple.com/library/ios/qa/qa1797/_index.html
我能够按照此 answer 以编程方式访问顶级指南。我正在为我的自定义 class 使用 XIB,因此无法通过图形界面构建器访问 topLayoutGuide
,如下所示。
相反 topLayoutGuide
可以通过 [self topLayoutGuide]
访问,其中 self 是 UIViewController
。 Documentation link
if ([self respondsToSelector:@selector(topLayoutGuide)]) {
id topGuide = [self topLayoutGuide];
NSDictionaryOfVariableBindings(topGuide ...
我已经阅读了 iOS 7 中关于自动布局和状态栏行为的多篇先前帖子,但仍然不知道如何让我的自动布局对象位于状态栏下方。
我目前有
self.automaticallyAdjustsScrollViewInsets = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;
并且搜索栏应用了视觉格式,如 V:|-0-searchBar-|
。
搜索栏呈现在状态栏下方
我一直找不到使搜索栏从状态栏底部边缘开始的解决方案。如何做到这一点?
编辑: 我查看了顶部布局选项,但我的自定义视图控制器有一个 xib。没有可用的顶部布局指南。我如何支持此设置?我想避免检查系统版本。
您需要使用topLayoutGuide
。
Apple 在这个问题上有很好的指南:https://developer.apple.com/library/ios/qa/qa1797/_index.html
我能够按照此 answer 以编程方式访问顶级指南。我正在为我的自定义 class 使用 XIB,因此无法通过图形界面构建器访问 topLayoutGuide
,如下所示。
topLayoutGuide
可以通过 [self topLayoutGuide]
访问,其中 self 是 UIViewController
。 Documentation link
if ([self respondsToSelector:@selector(topLayoutGuide)]) {
id topGuide = [self topLayoutGuide];
NSDictionaryOfVariableBindings(topGuide ...