iOS 7:UITableView 显示在状态栏下 [英] iOS 7: UITableView shows under status bar

查看:44
本文介绍了iOS 7:UITableView 显示在状态栏下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的第一个屏幕是一个 UITableViewController 没有导航栏,这意味着内容在状态栏下方流动,因此有很多文本冲突.我已经调整了 Under top barsAdjust scroll view insets 的属性,这实际上阻止它向下滚动,但代价是保持表格的顶部查看下.我试图将 UITableView 框架设置为偏移 20 像素,但它似乎没有生效,因为我目前需要该应用程序与 iOS 6 兼容,所以我无法跳转到iOS 7 Storyboards 强制自动布局使用顶部高度指南.有没有人找到适用于两个版本的解决方案?

The first screen of my application is a UITableViewController without a navigation bar, which means that the content flows under the status bar so there's a lot of text collisions. I've adjusted both the properties for Under top bars and Adjust scroll view insets which do actually stop it from scrolling under, but at the cost of keeping the top of the table view under. I've attempted to set the UITableView frame to offset by 20 pixels, but it doesn't appear to take effect and as I currently need the app to be compatible with iOS 6 I can't jump to iOS 7 Storyboards to force autolayout to use the top height guide. Has anyone found a solution that works for both versions?

我尝试过的事情:设置 edgesForExtendedLayout,更改 Storyboard 中 Under top barsAdjust scroll view 的设置,强制框架到一个新的领域.

Things I've tried: setting edgesForExtendedLayout, changing the settings within Storyboard for Under top bars and Adjust scroll view, forcing the frame to a new area.

一张图片胜过千言万语:

A picture is worth a thousand words:

推荐答案

对于任何有兴趣复制此内容的人,只需按照以下步骤操作:

For anyone interested in replicating this, simply follow these steps:

  1. 创建一个新的 iOS 项目
  2. 打开主故事板并删除默认/初始UIViewController
  3. 从对象库中拖出一个新的UITableViewController
  4. 将其设置为初始视图控制器
  5. 向表格提供一些测试数据

如果您按照上述步骤操作,当您运行应用程序时,您将看不到任何内容,包括将 Xcode 的复选框调整为在 {Top, Bottom, Opaque} Bars 下扩展边缘"可以阻止第一行出现在状态栏,您也无法以编程方式解决此问题.

If you follow the above steps, when you run the app, you will see that nothing, including tweaking Xcode's checkboxes to "Extend Edges Under {Top, Bottom, Opaque} Bars" works to stop the first row from appearing under the status bar, nor can you address this programmatically.

例如在上述情况下,以下内容将没有影响:

E.g. In the above scenario, the following will have no effect:

// These do not work
self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;

这个问题可能非常令人沮丧,我相信这是苹果公司的一个错误,特别是因为它出现在他们自己的对象库中的预连线 UITableViewController 中.

This issue can be very frustrating, and I believe it is a bug on Apple's end, especially because it shows up in their own pre-wired UITableViewController from the object library.

我不同意任何试图通过使用任何形式的幻数"来解决这个问题的人,例如使用 20px 的增量".这种紧耦合的编程绝对不是苹果想让我们在这里做的.

I disagree with everyone who is trying to solve this by using any form of "Magic Numbers" e.g. "use a delta of 20px". This kind of tightly coupled programming is definitely not what Apple wants us to do here.

我发现了两个解决此问题的方法:

I have discovered two solutions to this problem:

  • 保留UITableViewController的场景:
    如果您想将 UITableViewController 保留在故事板中,而不需要手动将其放入另一个视图中,您可以将 UITableViewController 嵌入到 UINavigationController (编辑器 > 嵌入 > 导航控制器)并在检查器中取消选中显示导航栏".这解决了这个问题,不需要额外的调整,它还可以在故事板中保留 UITableViewController 的场景.

  • Preserving the UITableViewController's scene:
    If you would like to keep the UITableViewController in the storyboard, without manually placing it into another view, you can embed the UITableViewController in a UINavigationController (Editor > Embed In > Navigation Controller) and uncheck "Shows Navigation Bar" in the inspector. This solves the issue with no extra tweaking needed, and it also preserves your UITableViewController's scene in the storyboard.

使用 AutoLayout 并将 UITableView 嵌入到另一个视图中 (我相信 Apple 希望我们这样做):
创建一个空的 UIViewController 并将您的 UITableView 拖入其中.然后,按住 Ctrl 键从 UITableView 向状态栏拖动.当鼠标到达状态栏的底部时,您会看到一个 Autolayout 气泡,上面写着Top Layout Guide".松开鼠标并选择垂直间距".这会告诉布局系统将它放在状态栏的正下方.

Using AutoLayout and embedding the UITableView into another view (I believe this is how Apple wants us to do this):
Create an empty UIViewController and drag your UITableView in it. Then, Ctrl-drag from your UITableView towards the status bar. As the mouse gets to the bottom of the status bar, you will see an Autolayout bubble that says "Top Layout Guide". Release the mouse and choose "Vertical Spacing". That will tell the layout system to place it right below the status bar.

我在一个空的应用程序上测试了这两种方式,它们都可以工作.您可能需要进行一些额外的调整,以使它们适用于您的项目.

I have tested both ways on an empty application and they both work. You may need to do some extra tweaking to make them work for your project.

这篇关于iOS 7:UITableView 显示在状态栏下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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