How prevent view under navbar in iMessage app exte

2019-09-14 16:30发布

I have the same issue in this post, i follow all recommended in that answers but notting works, in my case the difference is that i have a table view controller.

I have tried in many ways to prevent this from happening.

example:

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

Inside viewDidLoad:

    self.navigationController.navigationBar.translucent = NO;

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

This is my UITableViewController config:

enter image description here

This is exactly my problem:

enter image description here

Thanks for help.

2条回答
虎瘦雄心在
2楼-- · 2019-09-14 16:49

You can use constraints to the view.

Set a top View constraint for the compact view like:

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

Update your constraint on compact and expanded view in 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;
  }
}
查看更多
Bombasti
3楼-- · 2019-09-14 16:55

Have you tried with disabling under navigation bar appearance in your view controller? Put following in your init:

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

I've used Masonry AutoLayout library for setting up constraints and following snippet worked:

[_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;
查看更多
登录 后发表回答