iOS 7 自定义 TableView 在 TabBar 下

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19173630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:02:03  来源:igfitidea点击:

iOS 7 Custom TableView Is Under TabBar

iosobjective-cuiviewios7tableview

提问by Paulo Coutinho

Im trying port my app to iOS7, but my custom TableViewControlleris showing the last row (cell) under the TabBar:(

我正在尝试将我的应用程序移植到iOS7,但我的自定义TableViewController显示了TabBar:(

Im searching a lot for it, but i dont find any solution. Can anyone help me?

我搜索了很多,但我没有找到任何解决方案。谁能帮我?

My Custom Table View class

我的自定义表视图类

The error is shown in the blow screenshot (only is showing a part of last product because im draging to up to show the hidden product under the tabbar):

错误显示在吹屏截图中(仅显示上一个产品的一部分,因为我向上拖动以显示标签栏下的隐藏产品):

screenshot

截屏

Thanks.

谢谢。

采纳答案by Wojtek

I found the answer to your question on another post, answered by dariaa, here:

我在另一篇文章中找到了你的问题的答案,由 dariaa 在这里回答:

Tab Bar covers TableView cells in iOS7

Tab Bar 覆盖了 iOS7 中的 TableView 单元格

It worked great for me.

它对我很有用。

Please no credit for me, because I'm not the original guy who solved it.

请不要相信我,因为我不是解决它的原始人。

In your custom TableViewController, add these two lines under [super viewDidLoad]:

在您的自定义 TableViewController 中,在 [super viewDidLoad] 下添加这两行:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0); 
} 

回答by José Flávio

I've got the same problem and solved it using storyboard. At Tab Bar Controller, go to attribute inspector, Simulated Metrics, and set the Bottom Bar to Opaque Tab Bar. That's it! See image bellow for description. enter image description here

我遇到了同样的问题并使用故事板解决了它。在 Tab Bar Controller 中,转到属性检查器、Simulated Metrics,并将底部 Bar 设置为 Opaque Tab Bar。就是这样!有关说明,请参见下图。 在此处输入图片说明

Sauda??es! (Greetings!)

Sauda??es!(你好!)

回答by An Se

My friends, I cannot tell you how badly I struggled from this. Not a single re-configuration of Story Board never helped me. The issue was exactly like in Original Post, I've managed to fix it using:

我的朋友们,我无法告诉你们我为此挣扎了多少。没有一次重新配置 Story Board 从来没有帮助过我。这个问题与原始帖子中的完全一样,我设法使用以下方法修复它:

for swift 3

快速 3

self.edgesForExtendedLayout = []

for objective-c

对于目标-c

self.edgesForExtendedLayout = NO;

回答by Matthieu Riegler

2 lines in viewDidLoadand that's it !

2 行viewDidLoad,就是这样!

self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);

回答by Raheel Sadiq

In iOS 7 viewController uses full height. There is a property introduced as

在 iOS 7 viewController 使用全高。有一个属性介绍为

self.automaticallyAdjustsScrollViewInsets = NO;

set it to no. then check, or set UIEdgeInset if is not set right after it.

将其设置为否。然后检查或设置 UIEdgeInset 如果在它之后没有设置。

UIEdgeInsetsMake(top, left, bottom, right)

See here https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

请参阅此处 https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

Edit: try also this

编辑:也试试这个

self.edgesForExtendedLayout = UIRectEdgeNone;

回答by AmitP

The root cause of this problem is that automaticallyAdjustsScrollViewInsetsis effective only on the Firstscroll view in your VC's view Hierarchy. It is not documented by Apple, but it is the only way the VC will detect the scroll view needing to be modified unless you're using a UITableViewController.

这个问题的根本原因是,automaticallyAdjustsScrollViewInsets有效仅在第一次在VC的视图层次滚动视图。Apple 没有记录它,但这是 VC 检测需要修改的滚动视图的唯一方法,除非您使用 UITableViewController。

So in order to fix your issue without manually adjusting the insets, do this:

因此,为了在不手动调整插图的情况下解决您的问题,请执行以下操作:

  1. Make sure "Adjust Scroll View Insets" is checked.
  2. Make sure that the tableView is the firstsubview in the view Hierarchy. (Move it upwards above all other elements)
  1. 确保选中“调整滚动视图插入”。
  2. 确保 tableView 是视图层次结构中的第一个子视图。(将其向上移动到所有其他元素之上)

回答by Fruity Geek

UIViewController has two new properties to assist you : topLayoutGuideand bottomLayoutGuide. They return the height of the parent view controller's controls you need to avoid. In this case, bottomLayoutGuidewill return the offset of the tab bar.

UIViewController 有两个新属性可以帮助您:topLayoutGuidebottomLayoutGuide. 它们返回您需要避免的父视图控制器控件的高度。在这种情况下,bottomLayoutGuide将返回标签栏的偏移量。

Your custom view controller is probably overriding a method and not invoking super's implementation where this would be done for you. I am guessing you are installing AutoLayout constraints or setting a view's frame manually to fill the view. You just need to include the value from [bottomLayoutGuide length]to your layout calculation. If you support rotation, you should update that value in willAnimateRotationToInterfaceOrientation:duration:.

您的自定义视图控制器可能会覆盖一个方法,而不是调用super的实现来为您完成。我猜您正在安装 AutoLayout 约束或手动设置视图的框架以填充视图。您只需要[bottomLayoutGuide length]在布局计算中包含 from 的值。如果您支持轮换,则应在willAnimateRotationToInterfaceOrientation:duration:.

回答by Helge Becker

UINavigationControllerand UITabBarControllerboth have a transparency flag that can be set programmatically or in the storyboard.

UINavigationController并且UITabBarController两者都有一个透明标志,可以以编程方式或在故事板中设置。

The UINavigationControlleralso has two flags that control if the content extends under the top or bottom bar. Again you can set them programmatically or in the storyboard. This will apply to all subviews.

UINavigationController也有控制,如果内容在顶部或底部的条形码伸出两个标志。同样,您可以以编程方式或在故事板中设置它们。这将适用于所有子视图。

Each UIViewControllercan set its own preference in code. The property is called edgesForExtendedLayoutand you can set up all combinations.

每个人都UIViewController可以在代码中设置自己的偏好。属性被调用edgesForExtendedLayout,您可以设置所有组合。

Using those properties will allow AutoLayout and Springs'n'Struts to adjust the views the way you want them regardless of the device.

使用这些属性将允许 AutoLayout 和 Springs'n'Struts 以您想要的方式调整视图,而不管设备如何。

There are a lot more new properties in UIViewControllerthat you will want to have a look at.

还有更多的新属性UIViewController,你会想要看看。

回答by asolakhyan

Try the following:

请尝试以下操作:

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])

 self.edgesForExtendedLayout = UIRectEdgeBottom;

回答by Minas Kamel

I've got the same problem. One solution to it is to make the ToolBar notTranslucent. Here's how to do it:

我有同样的问题。一个解决方案是使工具栏透亮。这是如何做到的:

  • First select the tool bar from the document viewer like here
  • Then uncheck Translucentlike here

Hope this helps.

希望这可以帮助。

Thanks.

谢谢。