[英]iOS 7 Custom TableView Is Under TabBar
我尝试将我的应用程序iOS7
到iOS7
,但我的自定义TableViewController
显示TabBar
下的最后一行(单元格):(
我正在寻找它,但我没有找到任何解决方案。 谁能帮我?
该错误显示在打击屏幕截图中(仅显示最后一个产品的一部分,因为我正在向上展示以显示标签栏下的隐藏产品):
谢谢。
我有同样的问题,并使用故事板解决了它。 在Tab Bar Controller中,转到属性检查器,Simulated Metrics,然后将Bottom Bar设置为Opaque Tab Bar。 而已! 有关说明,请参见下图。
Saudações! (问候!)
我在另一篇文章中找到了你的问题的答案,由dariaa回答,在这里:
它对我很有用。
请不要相信我,因为我不是解决它的原始人。
在自定义TableViewController中,在[super viewDidLoad]下添加这两行:
- (void)viewDidLoad
{
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0);
}
我的朋友们,我不能告诉你我是多么挣扎。 没有一个故事板的重新配置从来没有帮助过我。 问题与原帖一样,我已设法使用以下方法修复它:
对于斯威夫特3
self.edgesForExtendedLayout = []
对于objective-c
self.edgesForExtendedLayout = NO;
viewDidLoad
2行,就是这样!
self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);
在iOS 7中,viewController使用全高。 有一个属性介绍为
self.automaticallyAdjustsScrollViewInsets = NO;
把它设为否。 然后检查,或设置UIEdgeInset如果没有在它之后设置。
UIEdgeInsetsMake(top, left, bottom, right)
编辑 :也尝试这个
self.edgesForExtendedLayout = UIRectEdgeNone;
此问题的根本原因是automaticallyAdjustsScrollViewInsets
仅在 VC的视图层次结构中的第一个滚动视图上有效 。 Apple没有记录它,但它是VC检测需要修改的滚动视图的唯一方法,除非您使用的是UITableViewController。
因此,为了在不手动调整insets的情况下修复问题,请执行以下操作:
UIViewController有两个新属性可以帮助您: topLayoutGuide
和bottomLayoutGuide
。 它们返回您需要避免的父视图控制器控件的高度。 在这种情况下, bottomLayoutGuide
将返回标签栏的偏移量。
您的自定义视图控制器可能会覆盖一个方法,而不是调用super
的实现,而这将为您完成。 我猜您正在安装AutoLayout约束或手动设置视图的框架以填充视图。 您只需要将[bottomLayoutGuide length]
的值包含在布局计算中。 如果您支持旋转,则应在willAnimateRotationToInterfaceOrientation:duration:
更新该值willAnimateRotationToInterfaceOrientation:duration:
.
UINavigationController
和UITabBarController
都有一个透明标志,可以通过编程或故事板设置。
UINavigationController
还有两个标志,用于控制内容是在顶部或底部栏下延伸。 您可以再次以编程方式或在故事板中设置它们。 这将适用于所有子视图。
每个UIViewController
都可以在代码中设置自己的首选项。 该属性称为edgesForExtendedLayout
,您可以设置所有组合。
使用这些属性将允许AutoLayout和Springs'n'Struts以您希望的方式调整视图,而不管设备如何。
UIViewController
中有许多新属性,您需要查看它们。
请尝试以下方法:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeBottom;
使用以下方法掩盖了问题:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 112, 0);
}
但它没有解决,因为在每个iPhone和每个app tableview上我底部有不同的空间。
所以这是一个糟糕的解决方案。
我不知道解决它的方法。
我现在解决了我的问题,将我的BaseTableViewController更改为从UIViewController继承到UITableViewController。
但是在UIViewController中使用TableView并没有解决:(
谢谢。
也许不是一个正确的答案,也是因为这个原因我发布这个答案,所以你可以告诉我这个答案是否可能是一个可能的解决方案。
在我的情况下,我喜欢半透明效果,所以我在表格中添加了一个页脚,我修改了scrollIndicators。
- (void)viewDidLoad
{
// Do any additional setup after loading the view.
[super viewDidLoad];
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.agendaItemsTable.frame.size.width, self.tabBarController.tabBar.frame.size.height)];
self.agendaItemsTable.tableFooterView = footer;
self.agendaItemsTable.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, self.tabBarController.tabBar.frame.size.height, 0);
}
你怎么看?
我遇到了同样的问题,而且投票的答案并没有解决。 请参阅我对类似问题的回答, Tab Bar涵盖了iOS7中的TableView单元格 。
我通过在表视图控制器的viewWillAppear:
方法中手动设置表视图的框架到屏幕高度来解决问题 - (状态栏高度+导航栏高度+标签栏高度)。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Adjust height of tableview (does not resize correctly in iOS 7)
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.height = [self heightForTableView];
self.tableView.frame = tableViewFrame;
}
- (CGFloat)heightForTableView
{
return CGRectGetHeight([[UIScreen mainScreen] bounds]) -
(CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) +
CGRectGetHeight(self.navigationController.navigationBar.frame) +
CGRectGetHeight(self.tabBarController.tabBar.frame));
}
如果有人找到更好的解决方案,请分享!
对于喜欢半透明效果的xarly和Autolayout解决方案(没有设置框架)的人,请参阅我的答案https://stackoverflow.com/a/26419986/1158074
我对集合视图有类似的问题。 更改集合视图框架和内容插入下面为我修复它...
guard let cv = collectionView,
let tabBar = tabBarController?.tabBar else { return }
// Resize collection view for tab bar
let adjustedFrame = CGRect(origin: cv.frame.origin,
size: CGSize(width: cv.frame.width, height: cv.frame.height - tabBar.frame.height))
cv.frame = adjustedFrame
// Adjust content inset for tab bar
let adjustedContentInsets = UIEdgeInsetsMake(0, 0, tabBar.frame.height, 0)
cv.contentInset = adjustedContentInsets
cv.scrollIndicatorInsets = adjustedContentInsets
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.