[英]Adding a view controller as a subview in another view controller
[英]Adding a subview to a view controller messes up with a table view
我有一个UIViewController
有一个UITableView
作为子视图。 我想在表格视图下添加一个背景视图,但是当我添加它时,控制器的edgesForExtendedLayout
似乎混乱了
这是对的:
这是不正确的:
我的viewDidLoad
方法看起来像这样。 如果我不添加子视图,则一切正常。
- (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]];
}
我认为此问题的解决方法是设置:
self.navigationController.navigationBar.translucent = FALSE;
self.edgesForExtendedLayout = UIRectEdgeNone;
看到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.