0

我在这篇文章中遇到了同样的问题,我遵循了该答案中的所有建议,但没有奏效,就我而言,不同之处在于我有一个表格视图控制器。

我已经尝试了很多方法来防止这种情况发生。

例子:

-(void)viewDidLayoutSubviews {

    //the next 2 lines was tested with self.tableView and self.view
    [self.view.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor constant:8.0].active = YES;
    [self.view constraintEqualToAnchor:[self.topLayoutGuide bottomAnchor]].active = YES;

    [self.tableView setContentInset:UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 0, 0)];

    self.automaticallyAdjustsScrollViewInsets = YES;
}

内部viewDidLoad

    self.navigationController.navigationBar.translucent = NO;

    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

这是我的UITableViewController配置:

在此处输入图像描述

这正是我的问题:

在此处输入图像描述

感谢帮助。

4

2 回答 2

0

您可以对视图使用约束。

为紧凑视图设置顶部视图约束,例如:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *searchViewTopConstraints;

在 presentRecentsViewControllerFor 中更新您对紧凑和扩展视图的约束:

-(void)presentRecentsViewControllerFor:(MSConversation*)conversation withPresentStyle:(MSMessagesAppPresentationStyle)presentationStyle
{
  tableViewC = [[UIStoryboard storyboardWithName:@"MainInterface" bundle:nil] instantiateViewControllerWithIdentifier:@"ShareRecents"];
  if (presentationStyle == MSMessagesAppPresentationStyleCompact) {
     NSLog(@"Compact view");
     tableViewC.searchViewTopConstraints.constant = 0;         
  } else
  {
    NSLog(@"Expanded view");
    [self.view.topAnchor constraintEqualToAnchor:[self.topLayoutGuide bottomAnchor]].active = YES;
  }
}
于 2017-02-01T14:09:31.733 回答
0

您是否尝试过在视图控制器中禁用导航栏下的外观?在您的初始化中放入以下内容:

self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;

我已经使用Masonry AutoLayout 库来设置约束并且以下代码段有效:

[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {

    make.left.equalTo(self.view.mas_left);
    make.top.equalTo(self.view.mas_top);
    make.right.equalTo(self.view.mas_right);
}];
[_collectionView.bottomAnchor constraintEqualToAnchor:[self.bottomLayoutGuide bottomAnchor]].active = YES;
于 2017-01-19T08:40:15.993 回答