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
iOS 7 Custom TableView Is Under TabBar
提问by Paulo Coutinho
Im trying port my app to iOS7
, but my custom TableViewController
is 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?
我搜索了很多,但我没有找到任何解决方案。谁能帮我?
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):
错误显示在吹屏截图中(仅显示上一个产品的一部分,因为我向上拖动以显示标签栏下的隐藏产品):
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.
我遇到了同样的问题并使用故事板解决了它。在 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 viewDidLoad
and 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)
Edit: try also this
编辑:也试试这个
self.edgesForExtendedLayout = UIRectEdgeNone;
回答by AmitP
The root cause of this problem is that automaticallyAdjustsScrollViewInsets
is 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:
因此,为了在不手动调整插图的情况下解决您的问题,请执行以下操作:
- Make sure "Adjust Scroll View Insets" is checked.
- Make sure that the tableView is the firstsubview in the view Hierarchy. (Move it upwards above all other elements)
- 确保选中“调整滚动视图插入”。
- 确保 tableView 是视图层次结构中的第一个子视图。(将其向上移动到所有其他元素之上)
回答by Fruity Geek
UIViewController has two new properties to assist you : topLayoutGuide
and bottomLayoutGuide
. They return the height of the parent view controller's controls you need to avoid. In this case, bottomLayoutGuide
will return the offset of the tab bar.
UIViewController 有两个新属性可以帮助您:topLayoutGuide
和bottomLayoutGuide
. 它们返回您需要避免的父视图控制器控件的高度。在这种情况下,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
UINavigationController
and UITabBarController
both have a transparency flag that can be set programmatically or in the storyboard.
UINavigationController
并且UITabBarController
两者都有一个透明标志,可以以编程方式或在故事板中设置。
The UINavigationController
also 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 UIViewController
can set its own preference in code. The property is called edgesForExtendedLayout
and 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 UIViewController
that you will want to have a look at.
还有更多的新属性UIViewController
,你会想要看看。
回答by asolakhyan
Try the following:
请尝试以下操作:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeBottom;