问题
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:
This is exactly my problem:
Thanks for help.
回答1:
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;
回答2:
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;
}
}
来源:https://stackoverflow.com/questions/41707159/how-prevent-view-under-navbar-in-imessage-app-extension