I have a UIViewController
that has a UITableView
as a subview. I want to add a background view under the table view but when I add it, the controller's edgesForExtendedLayout
seem to be messed up
This is correct:
This is not correct:
My viewDidLoad
method looks like this. If I do not add the subview, all looks ok.
- (void)viewDidLoad
{
[super viewDidLoad];
// UITableView
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:TAManeuvreCellId];
[self.view addSubview:self.tableView];
UIView *backgroundBlurView = [[UIView alloc] init];
// autolayout
backgroundBlurView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *views = NSDictionaryOfVariableBindings(backgroundBlurView, _tableView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_tableView]|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_tableView]|" options:0 metrics:nil views:views]];
// comment this and everything is ok
[self.view addSubview:backgroundBlurView];
[self.view sendSubviewToBack:backgroundBlurView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[backgroundBlurView]|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[backgroundBlurView]|" options:0 metrics:nil views:views]];
}
I think the fix for this is setting:
See:
How to prevent UINavigationBar from covering top of view in iOS 7?
iOS 7 UIImagePickerController navigationbar overlap