4

我正在通过以下方式使用输入附件视图。

override var canBecomeFirstResponder: Bool {
    return true
}

override var inputAccessoryView: UIView? {
    return self.userInputView
}

另外,在 viewDidAppear 方法中,我输入:

let _ = self.becomeFirstResponder()

在我的情况下这是必须的,因为我的 viewController 是 childViewController。

无论如何,我不知道为什么,但是当我呈现 UIAlertController 并且键盘处于活动状态时,键盘会关闭,inputAccessoryView 也会消失,然后突然出现在 UIAlertController 上方。

有没有人经历过这样的事情?

谢谢

编辑 - 添加图片: 在 UIAlertController 上显示

4

1 回答 1

0

这将解决..!

不要使用名称'inputAccessoryView

- (UIView *)CustominputAccessoryView { if (!keyboardinputAccessoryView) { CGRect accessFrame = CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 40.0); keyboardinputAccessoryView = [[UIView alloc] initWithFrame:accessFrame]; keyboardinputAccessoryView.backgroundColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.6]; UIButton *compButton = [UIButton buttonWithType:UIButtonTypeCustom]; compButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-60, 0.0, 50, 40.0); [compButton setTitle: @"Done" forState:UIControlStateNormal]; compButton.titleLabel.textColor = [UIColor blueColor]; [compButton setTitleColor:self.view.tintColor forState:UIControlStateNormal]; [compButton addTarget:self action:@selector(completeCurrentWord:) forControlEvents:UIControlEventTouchUpInside]; [keyboardinputAccessoryView addSubview:compButton]; } return keyboardinputAccessoryView; }

keyboardinputAccessoryView 只是一个 UIView

@property (readonly, retain) UIView *keyboardinputAccessoryView;

然后将'CustominputAccessoryView'作为你的textField的inputAccessoryView

    - (void)textFieldDidBeginEditing:(UITextField *)textField 
{
 textField.inputAccessoryView = [self CustominputAccessoryView];
}
于 2016-12-02T07:13:54.703 回答