自定义键盘InputAccessoryView在iOS 11中不可见

自定义键盘InputAccessoryView在iOS 11中不可见,ios,keyboard,inputaccessoryview,Ios,Keyboard,Inputaccessoryview,我已经实现了自定义输入附件视图,它在iOS 10.3.1之前运行良好。但它在iOS 11测试版中不可见 有人遇到过这个问题吗?你问的问题没有太多细节。但是我在为文本字段使用inputAccessoryView和自定义inputView时遇到了同样的问题 并在iOS11上通过将自定义inputView的autoresizingMask设置为.flexibleHeight解决了此问题 yourCustomInputView.autoresizingMask = .flexibleHeight 希望

我已经实现了自定义输入附件视图,它在iOS 10.3.1之前运行良好。但它在iOS 11测试版中不可见


有人遇到过这个问题吗?

你问的问题没有太多细节。但是我在为文本字段使用inputAccessoryView和自定义inputView时遇到了同样的问题

并在iOS11上通过将自定义inputView的autoresizingMask设置为.flexibleHeight解决了此问题

yourCustomInputView.autoresizingMask = .flexibleHeight
希望这能解决问题。如果没有,请提供更多信息

以下是我如何添加输入附件,以防有更多帮助(作为textfield的扩展):

}


然后在inputView(而不是inputAccessoryView)上,我使用了一个日期选择器,例如-只需确保日期选择器的自动调整大小掩码设置为灵活的高度。

Beta 3刚刚推出,一些人说它解决了问题,但对我来说它没有

然而,我尝试将附件视图设置为一些愚蠢的设置(100pxls高),发现iPad上的撤销/重做/粘贴栏错误地位于附件栏的顶部。 因此,我添加了以下代码来摆脱苹果条(这对我的自定义选择器来说毫无意义),问题就消失了

希望这对某人有帮助

- (void)textFieldDidBeginEditing:(UITextField*)textField  
{  
    UITextInputAssistantItem* item = [textField inputAssistantItem];  
    item.leadingBarButtonGroups = @[];  
    item.trailingBarButtonGroups = @[];  
}  

我也遇到过同样的问题,我发现删除所有的
底部
顶部
前导
培训
约束
分配的视图
accessoryView
解决了它。

PSA:如果您使用UIToolbar作为自定义视图,它当前在iOS 11gm中被破坏。 不必为如何修复头发而烦恼,只需将其更改为UIView
你会失去模糊效果,但它会起作用。

UIToolBar在iOS 11中被破坏。但是使用UIView和inputAccessoryView可以完成相同的工作。此处是示例代码段:

CGFloat width = [[UIScreen mainScreen] bounds].size.width;
UIView* toolBar = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f, width, 44.0f)];
toolBar.backgroundColor = [UIColor colorWithRed:0.97f  green:0.97f blue:0.97f alpha:1.0f];

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0 , 0.0f, width, 44.0f)];
[titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:13]];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor redColor]];
[titleLabel setText:@"Title"];
[titleLabel setTextAlignment:NSTextAlignmentLeft];
[toolBar addSubview:titleLabel];

UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[doneBtn setTitle:@"Done" forState:UIControlStateNormal];
doneBtn.tintColor = [UIColor colorWithRed:(float)179/255 green:(float)27/255 blue:(float)163/255 alpha:1];
[doneBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
[doneBtn addTarget:self action:@selector(btnTxtDoneAction) forControlEvents:UIControlEventTouchUpInside];
[doneBtn setFrame:CGRectMake(width-70, 6, 50, 32)];
[toolBar addSubview:doneBtn];

[toolBar sizeToFit];

txtMessageView.inputAccessoryView = toolBar;

希望有此帮助:)

要避免iOS 11中针对
UITextField
UITextView
inputAccessoryView
问题,只需使用以下代码:

UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];

self.monthPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];

    self.monthPickerView.backgroundColor = [UIColor whiteColor];

    self.monthPickerView.delegate = self;

    self.monthPickerView.dataSource = self;
[inputView addSubview:self.monthPickerView];

    cell.monthTextField.inputView = inputView ;

self.monthTextField.inputAccessoryView = [self doneButtonAccessoryView];


// doneButtonAccessoryView Method


-(UIToolbar*)doneButtonAccessoryView
{

    UIToolbar *kbToolbar = [[UIToolbar alloc] init];
    [kbToolbar sizeToFit];
    [kbToolbar setBarTintColor:[UIColor whiteColor]];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                   style:UIBarButtonItemStyleDone target:self
                                                                  action:@selector(doneClicked)];

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
                                                                     style:UIBarButtonItemStyleDone target:self
                                                                    action:@selector(cancelClicked)];
    NSDictionary *attrDict;

    attrDict = [NSDictionary dictionaryWithObjectsAndKeys:
                [UIFont fontWithName:@"Helvetica-Bold" size:16.0], NSFontAttributeName, nil];
 [doneButton setTitleTextAttributes:attrDict forState:UIControlStateNormal];
    UIBarButtonItem *flexWidth = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                               target:self action:nil];

    [kbToolbar setItems:[NSArray arrayWithObjects:cancelButton,flexWidth, doneButton, nil]];
    return kbToolbar;
}
Swift 4解决方案

let toolBarRect = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 44)
let toolBar = UIView(frame: toolBarRect)
toolBar.backgroundColor = .lightGray

let nextButton = UIButton()
nextButton.setTitleColor(.black, for: .normal)
nextButton.setTitle("Next", for: .normal)
nextButton.addTarget(self, action: #selector(self.onNextButtonTouch), for: .touchUpInside)
nextButton.translatesAutoresizingMaskIntoConstraints = false
toolBar.addSubview(nextButton)

NSLayoutConstraint.activate(
    [
        nextButton.heightAnchor.constraint(equalToConstant: Constants.keyboardToolBarHeight),
        nextButton.trailingAnchor.constraint(equalTo: toolBar.trailingAnchor, constant: -16),
        nextButton.centerYAnchor.constraint(equalTo: toolBar.centerYAnchor, constant: 0)
    ]
)

self.yourTextField.inputAccessoryView = toolBar

以防有人仍然需要解决方案,以下是我所做的(IOS 12.1)


添加更多细节。我看到了同样的事情。我的输入附件视图没有显示。这里有一个完整的答案给未来的观众:它不是一个吊舱
inputView.autoresizingMask=.flexibleHeight
在大多数情况下都会解决此问题。我也遇到过同样的问题,但此解决方案不适用于我。另外,我只在iPad上看到了这个问题,其他设备都可以,所以在iPad上这样做似乎很奇怪。这个解决方案对我也不起作用。我在iPhone上看到了这个问题。我在iOS 11.0.1中遇到了旋转附件视图错误的问题,并添加了。flexibleHeight解决了这个问题。这应该是可以接受的答案。inputView?.autoresizingMask=.flexibleHeight就可以解决这个问题。这在我的iOS 13应用程序中成为一个问题,设置它可以解决这个问题,谢谢!
let toolBarRect = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 44)
let toolBar = UIView(frame: toolBarRect)
toolBar.backgroundColor = .lightGray

let nextButton = UIButton()
nextButton.setTitleColor(.black, for: .normal)
nextButton.setTitle("Next", for: .normal)
nextButton.addTarget(self, action: #selector(self.onNextButtonTouch), for: .touchUpInside)
nextButton.translatesAutoresizingMaskIntoConstraints = false
toolBar.addSubview(nextButton)

NSLayoutConstraint.activate(
    [
        nextButton.heightAnchor.constraint(equalToConstant: Constants.keyboardToolBarHeight),
        nextButton.trailingAnchor.constraint(equalTo: toolBar.trailingAnchor, constant: -16),
        nextButton.centerYAnchor.constraint(equalTo: toolBar.centerYAnchor, constant: 0)
    ]
)

self.yourTextField.inputAccessoryView = toolBar
private func initSearchBox() {
    
    // Add Done button on keyboard      
    txtSearch.delegate = self
    let tbrDone = UIToolbar()
    let btnDone = UIBarButtonItem(title: "Done", style: .plain, target: self, action:     #selector(btnDone_tapped))
    tbrDone.items = [btnDone]
    tbrDone.sizeToFit()
    self.txtSearch.inputAccessoryView = tbrDone
        
}
    
@objc func btnDone_tapped() {

    view.endEditing(true)
        
}