【发布时间】:2017-09-13 18:10:02
【问题描述】:
我正在以编程方式创建 UIToolBar,它工作正常,除了 iPhone X,我希望工具栏根据手机的方向展开。如果工具栏是使用界面生成器创建的,则扩展工作。
我没有设置任何高度限制,即使是通过自动布局掩码隐式设置。
代码:
UIToolbar* toolbar = [[UIToolbar alloc] init];
toolbar.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:toolbar];
[self.view addConstraints:@[
[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:toolbar attribute:NSLayoutAttributeLeft multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:toolbar attribute:NSLayoutAttributeBottom multiplier:1 constant:0],
[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:toolbar attribute:NSLayoutAttributeRight multiplier:1 constant:0]]];
那么,我应该怎么做才能使工具栏正常运行?
【问题讨论】: