我想使用可视格式化语言在代码中使用自动布局将视图emptyAddButton放置在左下角。这是我目前的方法。
初始化按钮emptyAddButton,自定义 UIViewController:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
...
emptyAddButton = [[AddCardViewController alloc] init];
[emptyAddButton.view setFrame:CGRectMake(50, 300, 190, 65)]; //to define width + height. x, y is random and should be overwritten by auto auto layout
[self addChildViewController:emptyAddButton];
[emptyAddButton.view setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:emptyAddButton.view];
...
}
为左下位置 + 填充分配自动布局 (10)
-(void)viewWillAppear:(BOOL)animated{
...
NSDictionary *viewToLayout = [NSDictionary dictionaryWithObject:emptyAddButton.view forKey:@"emptyAddButton"];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(10)-[emptyAddButton]"
options:0
metrics:nil
views:viewToLayout]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat: @"V:[emptyAddButton]-(10)-|"
options:0
metrics:nil
views:viewToLayout]];
...
}
目前emptyAddButton根本不显示。
知道如何正确定位视图吗?