我有一个消息传递应用程序,它具有全屏表格视图底部的文本字段的典型UI设计.我将该文本字段设置为视图控制器inputAccessoryView并调用ViewController.becomeFirstResponder()以使字段显示在屏幕底部.
我知道这是Apple推荐的实现这种UI结构的方法,它在"经典"设备上运行得很好但是当我在iPhone X模拟器上测试时,我注意到使用这种方法,文本字段不尊重新的"安全区域" .文本字段显示在主屏幕指示器下方屏幕的最底部.
我查看了HIG文档,但没有找到任何关于inputAccessoryView视图控制器的有用信息.
这很难,因为使用这种方法我实际上并没有直接控制任何约束,我只是设置inputAccessoryView并让视图控制器从那里处理UI.所以我不能仅仅把这个领域限制在新的安全区域.
有没有人在这方面找到了很好的文档,或者知道在iPhone X上运行良好的替代方法?
我有一个已知的问题,即将UIButton添加到UIBarButtonItem中.我已尝试添加自动布局约束,如stackoveflow中所示,但我收到如下所述的错误.
UIButton *sortButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sortButton setFrame:CGRectMake(10, 0, 100, 30)];
[sortButton setTitle:@"Sort" forState:UIControlStateNormal];
[[sortButton titleLabel] setFont:[UIFont boldSystemFontOfSize:13]];
[sortButton setBackgroundImage:[UIImage imageNamed:@"backgroun-button.png"] forState:UIControlStateNormal];
[sortButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[sortButton addTarget:self action:@selector(sortCollection:) forControlEvents:UIControlEventTouchUpInside];
[sortButton applyNavBarConstraints:100 height:30];
[self setSortCollection:item];
[self setToolbarItems:[NSArray arrayWithObjects:self.sortCollection, nil]];
Run Code Online (Sandbox Code Playgroud)
Autolayout约束:
- (void)applyNavBarConstraints:(CGFloat)width height:(CGFloat)height
{
if (width == 0 || height == 0) {
return;
}
NSLayoutConstraint* w = [self.widthAnchor constraintEqualToConstant:width];
NSLayoutConstraint * h = [self.heightAnchor constraintEqualToConstant:height];
[w setActive:YES];
[h setActive:YES];
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
[LayoutConstraints] Unable to simultaneously satisfy constraints. …Run Code Online (Sandbox Code Playgroud)