2

当应用程序处于多任务模式时,我有一个宽度不变的 UIToolbar。

 self.toolBarKeyboard = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
 self.textfieldUserID.inputAccessoryView = self.toolBarKeyboard;

我尝试通过在此方法内部viewDidLayoutSubviews调用来更新 toolBarKeyboard 的框架。self.toolBarKeyboard = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];

我尝试如下向工具栏添加约束,但这也无济于事。

 self.toolBarKeyboard.translatesAutoresizingMaskIntoConstraints = NO;

[self.toolBarKeyboard addConstraint:[NSLayoutConstraint constraintWithItem:self.toolBarKeyboard attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.toolBarKeyboard.superview attribute:NSLayoutAttributeWidth multiplier:1 constant:0.0]];

self.toolBarKeyboard = [[UIToolbar alloc] init];
self.textfieldUserID.inputAccessoryView = self.toolBarKeyboard;
[self.toolBarKeyboard addConstraint:[NSLayoutConstraint constraintWithItem:self.toolBarKeyboard attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:nil multiplier:1 constant:44.0]];

当我将视图从水平紧凑类(多任务模式)更改为水平常规类时,工具栏不会调整大小。知道我在这里缺少什么吗?

在此处输入图像描述

4

0 回答 0