简体   繁体   English

iOS 7自定义TableView位于TabBar下

[英]iOS 7 Custom TableView Is Under TabBar

Im trying port my app to iOS7 , but my custom TableViewController is showing the last row (cell) under the TabBar :( 我尝试将我的应用程序iOS7iOS7 ,但我的自定义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): 该错误显示在打击屏幕截图中(仅显示最后一个产品的一部分,因为我正在向上展示以显示标签栏下的隐藏产品):

截图

Thanks. 谢谢。

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. 在Tab Bar Controller中,转到属性检查器,Simulated Metrics,然后将Bottom Bar设置为Opaque Tab Bar。 That's it! 而已! See image bellow for description. 有关说明,请参见下图。 在此输入图像描述

Saudações! Saudações! (Greetings!) (问候!)

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); 
} 

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: 问题与原帖一样,我已设法使用以下方法修复它:

for swift 3 对于斯威夫特3

self.edgesForExtendedLayout = []

for objective-c 对于objective-c

self.edgesForExtendedLayout = NO;

2 lines in viewDidLoad and that's it ! viewDidLoad 2行,就是这样!

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

In iOS 7 viewController uses full height. 在iOS 7中,viewController使用全高。 There is a property introduced as 有一个属性介绍为

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;

The root cause of this problem is that automaticallyAdjustsScrollViewInsets is effective only on the First scroll view in your VC's view Hierarchy. 此问题的根本原因是automaticallyAdjustsScrollViewInsets 仅在 VC的视图层次结构中的第一个滚动视图上有效 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. Apple没有记录它,但它是VC检测需要修改的滚动视图的唯一方法,除非您使用的是UITableViewController。

So in order to fix your issue without manually adjusting the insets, do this: 因此,为了在不手动调整insets的情况下修复问题,请执行以下操作:

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

UIViewController has two new properties to assist you : topLayoutGuide and bottomLayoutGuide . UIViewController有两个新属性可以帮助您: topLayoutGuidebottomLayoutGuide 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. 在这种情况下, bottomLayoutGuide将返回标签栏的偏移量。

Your custom view controller is probably overriding a method and not invoking super 's implementation where this would be done for you. 您的自定义视图控制器可能会覆盖一个方法,而不是调用super的实现,而这将为您完成。 I am guessing you are installing AutoLayout constraints or setting a view's frame manually to fill the view. 我猜您正在安装AutoLayout约束或手动设置视图的框架以填充视图。 You just need to include the value from [bottomLayoutGuide length] to your layout calculation. 您只需要将[bottomLayoutGuide length]的值包含在布局计算中。 If you support rotation, you should update that value in willAnimateRotationToInterfaceOrientation:duration: . 如果您支持旋转,则应在willAnimateRotationToInterfaceOrientation:duration:更新该值willAnimateRotationToInterfaceOrientation:duration: .

UINavigationController and UITabBarController both have a transparency flag that can be set programmatically or in the storyboard. UINavigationControllerUITabBarController都有一个透明标志,可以通过编程或故事板设置。

The UINavigationController also has two flags that control if the content extends under the top or bottom bar. UINavigationController还有两个标志,用于控制内容是在顶部或底部栏下延伸。 Again you can set them programmatically or in the storyboard. 您可以再次以编程方式或在故事板中设置它们。 This will apply to all subviews. 这将适用于所有子视图。

Each UIViewController can set its own preference in code. 每个UIViewController都可以在代码中设置自己的首选项。 The property is called edgesForExtendedLayout and you can set up all combinations. 该属性称为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中有许多新属性,您需要查看它们。

Try the following: 请尝试以下方法:

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

 self.edgesForExtendedLayout = UIRectEdgeBottom;

I've got the same problem. 我有同样的问题。 One solution to it is to make the ToolBar not Translucent. 一个解决方案是使ToolBar 不是半透明的。 Here's how to do it: 这是怎么做的:

Hope this helps. 希望这可以帮助。

Thanks. 谢谢。

The problem was masked using: 使用以下方法掩盖了问题:

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 112, 0);
}

But it doesn't solve, because on each iPhone and on each app tableview i have a different space on bottom. 但它没有解决,因为在每个iPhone和每个app tableview上我底部有不同的空间。

So this is a poor solution. 所以这是一个糟糕的解决方案。

I dont know a way to solve it. 我不知道解决它的方法。

I solved my problem now, changing my BaseTableViewController to inherit from UIViewController to UITableViewController. 我现在解决了我的问题,将我的BaseTableViewController更改为从UIViewController继承到UITableViewController。

But using a TableView inside a UIViewController is not solved :( 但是在UIViewController中使用TableView并没有解决:(

Thanks. 谢谢。

maybe is not a right answer, also for that reason I post this answer so you can tell me if this answer could be a possible solution. 也许不是一个正确的答案,也是因为这个原因我发布这个答案,所以你可以告诉我这个答案是否可能是一个可能的解决方案。

In my case, I like the translucent effect, so I have added a footer in the table and I have modified the scrollIndicators. 在我的情况下,我喜欢半透明效果,所以我在表格中添加了一个页脚,我修改了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);

}

What do you think? 你怎么看?

I had the same problem, and the up-voted answers did not solve it. 我遇到了同样的问题,而且投票的答案并没有解决。 See my answer to a similar question, Tab Bar covers TableView cells in iOS7 . 请参阅对类似问题的回答, Tab Bar涵盖了iOS7中的TableView单元格

I solved the issue by manually setting the table view's frame in the table view controller's viewWillAppear: method to the height of the screen - (status bar height + nav bar height + tab bar height). 我通过在表视图控制器的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));
}

If anyone finds a better solution to this problem, please share! 如果有人找到更好的解决方案,请分享!

对于喜欢半透明效果xarlyAutolayout解决方案(没有设置框架)的人,请参阅我的答案https://stackoverflow.com/a/26419986/1158074

I had a similar problem with collection view. 我对集合视图有类似的问题。 Changing the collection view frame and content inset below fixed it for me... 更改集合视图框架和内容插入下面为我修复它...

    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

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM