如何在iMessage应用扩展程序中阻止导航栏下的视图

时间:2017-01-17 21:17:17

标签: ios objective-c ios-app-extension imessage imessage-extension

我在this post中遇到了同样的问题,我遵循了所有建议的答案,但注意到工作,在我的情况下区别在于我有一个表视图控制器。

  

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

示例:

-(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配置:

enter image description here

这正是我的问题:

enter image description here

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您是否尝试过在视图控制器中导航栏外观下禁用? 在你的init中添加以下内容:

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;

答案 1 :(得分: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;
  }
}