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

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

问题描述

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

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中设置在顶栏下面调整滚动视图,将帧强制到新区域。

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. 为表格提供一些测试数据

  1. Create a new iOS project
  2. Open the main storyboard and delete the default/initial UIViewController
  3. Drag out a new UITableViewController from the Object Library
  4. Set it as the initial view controller
  5. Feed the table some test data

如果按照上述步骤操作,当你运行应用程序时,你将看到什么,包括将Xcode的复选框调整为在{顶部,底部,不透明}条形图下延伸条形图可以阻止第一行显示在状态栏下,也不能以编程方式解决此问题。

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.

EG在上面的场景中,以下内容将具有效果:

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;

这个问题非常令人沮丧,我相信这是Apple的一个错误,特别是因为它从对象库中显示在他们自己的预先连线的 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的delta。这种紧密耦合的编程绝对不是Apple希望我们在这里做的。

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 。然后,从 UITableView 按住Ctrl键拖动到状态栏。当鼠标到达状态栏的底部时,您将看到一个显示顶部布局指南的Autolayout气泡。释放鼠标并选择垂直间距。这将告诉布局系统将其放置在状态栏的正下方。

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天全站免登陆